Re: unix timestamp, strtotime, date, odd behavior?

From: Date: Thu, 17 Oct 2002 21:51:38 +0000
Subject: Re: unix timestamp, strtotime, date, odd behavior?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-120412@lists.php.net to get a copy of this message
It's a simple matter of timezones--Robert is right. date() probably thinks it's not daylight savings for some reason. Try this: <? $original = strtotime ("04 October 2002 12:00:00 AM EST"); $week = strtotime("18 October 2002 12:00:00 AM EST"); $nov1 = strtotime("1 November 2002 12:00:00 AM EST"); echo "This is Oct. 04: $original\n"; echo "<br>This is Oct. 18: $week\n"; $two_week = 60 * 60 * 24 * 14; $next = $week + $two_week; $datestamp = date("r (\D\S: I)", $next); echo "<br>This is a 14 day time period: $two_week\n"; echo "<br>This is the next timestamp: $next\n"; echo "<br>This is two weeks from Oct. 18: $datestamp\n"; echo "<br>This is Nov. 1: $nov1\n"; ?> Notice that I've changed your date() statement to print out whether *it* thinks daylight savings is on or not. Date is therefore a bit tricky, but as long as you keep consistent in your timezones you should have no problem taking care of this. Marco On Thu, 2002-10-17 at 17:28, Catherine Pinatiello wrote: > Since unix timestamp is simply seconds, then I figured you could take > the number of seconds for a two week period (14 days): 1209600 and add > it to any particular timestamp and then you could convert it back to a > formatted date using the date() function... > > Only thing is.. it's exhibiting odd behavior. > > I have a script running that has this output: > > This is today: 1034889084 > This is Oct. 04: 1033714800 > This is Oct. 18: 1034924400 > This is a 14 day time period: 1209600 > This is the next timestamp: 1036134000 > This is two weeks from Oct. 18: October, 31, 2002 > > This script does this: > > find timestamp for now > find timestamp for Oct. 4 > find timestamp for Oct. 18 > Oct. 18 - Oct. 4 = 14 day time period > Oct. 18 + 14 day time period timestamp > date func. to find date on resulting timestamp > > As you can see it thinks Oct. 31 is two weeks from Oct. 18, when in > actuality Nov. 1st is. So I figured it was off by one day so I'd > compensate and tried to find 2 weeks from Oct. 19 instead... and it gave > me November 2nd! The correct day from Oct. 19! ;) > > So I can't find the correct 2 week date from Oct. 18!! ;) I'm afraid it > will fail for other dates too? Am I doing something wrong? > > here's my code: > > $today = strtotime ("now"); > $original = strtotime ("04 October 2002"); > $week = strtotime("18 October 2002"); > > echo "This is today: $today<br>"; > echo "This is Oct. 04: $original"; > echo "<br>This is Oct. 18: $week"; > > $two_week = $week - $original; > $next = $week + $two_week; > $datestamp = date("F, j, Y", $next); > > echo "<br>This is a 14 day time period: $two_week"; > echo "<br>This is the next timestamp: $next"; > echo "<br>This is two weeks from Oct. 18: $datestamp"; > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >

« previous php.general (#120412) next »