Forum Moderators: coopster

Message Too Old, No Replies

How to add 3 hrs to my DATESTAMP?

         

irock

1:31 am on Aug 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi, I have this line in my PHP program, and I was wondering how I can adjust to to Eastern time (3 hrs ahead of PST).

$date = date("Ymdhh0000");

The date format I want is 20030804120000

Thanks!

Jeff_H

2:03 am on Aug 24, 2003 (gmt 0)

10+ Year Member



If your server is in PST, then just adding three hours to the current hour will work:

$date = date("Ymdh0000", mktime(date("h")+3));

Otherwise this might be better as it should work regardless of the server time:

$date = gmdate("Ymdh0000", mktime(date("h")-5));

P.S: you put an extra "h" in the date format

irock

4:46 am on Aug 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Jeff_H,

Doesn't seem to be working since this line don't adjust the date.

$date = date("Ymdh0000", mktime(date("h")+3));

For example, EST is supposed to be 12:45am the next day right now when PST is still 9:45pm August 23th, but the date returns 20030823120000. I was expecting 20030824120000.

Is there a workaround to this problem?

Thanks again for your help!

Jeff_H

6:26 am on Aug 24, 2003 (gmt 0)

10+ Year Member



I wonder if you server is maybe 12 hours off, i.e. it was actually 9:45am and adding three hours showed 12:45pm on the same date. When I try the syntax on my server, it has no problem updating the day, month, and year as neccessary.

Perhaps someone else can shed some light on this?

Try date("a") to see if the AM/PM are correct. If they are, the problem is beyond me :).

irock

6:32 am on Aug 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Jeff,

When I type 'uptime' in Telnet, the time is correct.

Hmm...

Jeff_H

6:40 am on Aug 24, 2003 (gmt 0)

10+ Year Member



Strange... what about when you do:

$date = date("Ymdh0000", mktime(date("h")+9999));

What is the result of that?

irock

6:47 am on Aug 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I got this
20041013020000

irock

6:55 am on Aug 24, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think I fixed the problem by adjusting to 'h' to 'H', which is military time... I think date here can get confused if not specified the Ante meridiem and Post meridiem correctly.

$now = date("YmdH0000 D");
$date = date("YmdH0000 D", mktime(date("H")+3));
print "$now -> $date";

OUTPUT:
20030823230000 Sat -> 20030824020000 Sun

Not sure if the my PHP implementation is different than yours... if so, that could explain the discrepancy of our results.

THanks!