Re: unix timestamp, strtotime, date, odd behavior?
| From: | Catherine Pinatiello | Date: | Thu, 17 Oct 2002 21:56:25 +0000 |
| Subject: | Re: unix timestamp, strtotime, date, odd behavior? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-120410@lists.php.net to get a copy of this message | ||
Okay, so adding an hour to 1209600 should fix it then? And shouldn't that work no matter what daylight savings or whatever is set to, since it's just an hour further into the day...?
Robert Cummings wrote:
You logic is off by an hour... probably the very same hour we will lose when the clocks go forward shortly for daylight savings. Cheers, Rob. 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