user778326
user778326

Reputation: 11

Timestamp Troubles

I have a snippet of code where I want to show the date and time for every time a client uses a discount card. Clients can not have more than two entries per card. However, when I try to display the two entries with the appropriate formatting only the older timestamp formats properly. Code below:

Last Used:

    <?php

    $timestamp = mysql_to_unix($row->trans_date);  //MySql Time stamp 2011-05-31 12:49:59
    date_default_timezone_set('America/Chicago');  //Push timestamp ahead 2 hours
    $lastuse = date('F j, Y @ g:i A', $timestamp); //format date

    echo $lastuse;


    ?>
     <?php endforeach; ?>

I have two timestamps coming in 1306871399 and 1306864204. The first stamp successfully processes as May 31, 2011 @ 2:49 PM, but the second comes out May 31, 2011 @ 12:50 PM.

I am not understanding why only one of the timestamps are being processed. Your feedback is appreciated.

Upvotes: 1

Views: 115

Answers (3)

Marc B
Marc B

Reputation: 360862

  1306871399
- 1306864204
------------
=       7195

7195 seconds = 1hr 59 minutes 55 seconds

May 31/2:49pm -> May31/12:50pm is about 1hr 59 minutes apart

So what's the problem?

Upvotes: 2

SQueryL
SQueryL

Reputation: 140

My thinking is that the older timestamp is not being passed through the timezone push, as it is 2 hours behind. Make sure your code is running both values through it.

If that's not it.. has your hosting provider changed recently? Server-time vs. Local-time could be an issue?

Upvotes: 1

landoncz
landoncz

Reputation: 2017

You should format your timestamp values for user-display at the MySQL level, instead of using PHP to format them. That way, you don't have to worry about what timezone your PHP server is on (your reference to the Chicago timezone). Try using the MySQL Date Format function to return a MySQL formatted timestamp as a string you can display...

Upvotes: 1

Related Questions