unix timestamp, strtotime, date, odd behavior?
| From: | Catherine Pinatiello | Date: | Thu, 17 Oct 2002 21:28:35 +0000 |
| Subject: | unix timestamp, strtotime, date, odd behavior? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-120405@lists.php.net to get a copy of this message | ||
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";