date display problem (gmdate ... as expected)[SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

date display problem (gmdate ... as expected)[SOLVED]

Post by m3rajk »

bebugging print out:
debug: final time: 10/11/2003 18:16:18
rel date: 10/11/2003 14:16:18
adjusted rel date: 10/11/2003 09:16:18
and the actual print out:
sick sick sick... 10/11/2003 13:16:18
the issue is that it saves the time as gmt, and the print out is off no matter what. the code to get the save date:

Code: Select all

$made=gmdate("Y-m-d H:i:s", time()); # find the date
and the display code:

Code: Select all

}elseif($fn=='list'){ # showing entry list

  $entries=mysql_query("SELECT beid,title,UNIX_TIMESTAMP(made) FROM blog WHERE buid='$buid' ORDER BY made DESC", $db);

  while($entry=mysql_fetch_array($entries)){ # while we can get entries

    $date=gmdate($utds, ($entry['UNIX_TIMESTAMP(made)']+($gmto*60*60))); # format the date of the entry
    $fd=gmdate($utds, $entry['UNIX_TIMESTAMP(made)']); # date without gmt offset (gmt time)
    $rd=date($utds, $entry['UNIX_TIMESTAMP(made)']); # date without gmt offset (local time)
    $rdo=date($utds, ($entry['UNIX_TIMESTAMP(made)']+($gmto*60*60))); # date with gmt offset (local time)

    $el.="        <tr>
            <td class="abcen"><a href="{$_SERVER['PHP_SELF']}?fn=show&buid=$buid&entry={$entry['beid']}" target="show"{$entry['title']}</a></td>
            <td class="abcen">$date</td>
          </tr>\n"; # create the entry listing
  }
  if($el!=''){ $disp=$el; } # make sure we display the right thing
  bgnpg("Displaying Journal Entries for $mtd");
  echo <<<END
      $tsw100
    <p>debug: final time: $fd <br /> rel date: $rd <br />adjusted rel date: $rdo</p>
$disp
      </table>
END;
  clspg();
}else{ # make the main page
the entry that got the dates at the begining were made at 10:16 est. i'm in est. i don't get why all of tose failed. i want to be able to make the times so it's irrelevant where i host the site, the display is local to the person viewing.
Last edited by m3rajk on Fri Oct 31, 2003 6:33 pm, edited 1 time in total.
Stoneguard
Forum Contributor
Posts: 101
Joined: Wed Aug 13, 2003 9:02 pm
Location: USA

Post by Stoneguard »

Well, I have not worked much with timestamps, but adding the 60*60*$gmto to the gmtimestamp does not seem right. Wouldnt that be adding minutes? 60 milliseconds * 60 seconds?

Anyway, when working with dates, it is important to remember that the server does not know what your local time is. I am not sure if there is a way to retrieve the local browser timezone, maybe in javascript.

Where is your server being hosted? The gmt date has 1800 hours on it, and your local date has 1400 hours. The server is only 4 hours from GMT according to those variables.
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

the server is a linux box a few rooms over (i'm on the east coast of the us, so est, actually isn't it edt right now?)

$gmto is actually set at the top of the file as the user's gmt offset (-12 to +12) and $utds is the user's time display style choice

i figure that the 4 hour diff instead of 5 is caused by edt instead of est. since i don't take edt into effect, that could explain the issue with 9 v 10 using local time, but since that could change if the host when i find an actual host is in a differnt time zone, i don't want to rely on it.

this begs the question, is there something wrong with how i stored it initially since that stored it 3 hours more than the offset. i can understand if it had been off by an hour because of the est/edt thing, but this i don't get, i don't understand what went wrong with the gmdate call that set made, which i think might be where the issue is. but like i said, i know she wrote that at 10:14 est
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

I FIGURED IT OUT!!!!!!!!!!


the cause of why this only occurs on some places: some of the places i do date work correctly because they use my toTimeStamp function which expects it to be in gmt to strat..
the ones that have an extra four ohour discrepency have it because they use the MySQL UNIX_TIMESTAMP() function, which expects it to be local to your server and ADJUSTS IT TO GMT so that you may adjust it correctly for your use with ease., thus adding an extra four hours.... the exact discrepency!!!
Post Reply