Problems with dates (bug?)
| From: | Nicholas Pappas | Date: | Mon, 19 Jun 2000 23:12:03 +0000 |
| Subject: | Problems with dates (bug?) | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-2252@lists.php.net to get a copy of this message | ||
I seem to have run into something that I can't explain away
logically... so obviously it is a bug, right! :)
What I have is a date stamp in the form YYYYMMDD. I am breaking that
up and converting it to a timestamp via mktime(), adding 86400 seconds
to it (1 day) and then converting it back to YYYYMMDD.
This seemed easier then adding/subtracting the days, checking to see if
I should wrap to 01 and advance the month, then check to see if I need
to wrap the month to 01 and advance the year. But maybe not...
The problem I am having is that 19991031 doesn't advance!
Convert it to a timestamp, add 86400, then convert it back to a
YYYYMMDD time stamp. It is still 19991031 according to 2 servers I have
run this on!
Adding 86400 to any other day seems to work, except this one. I found
that if I crank the value up to 90000 it will work, but that starts
skipping days when added to other timestamps.
Please check out this example program below... call it up in a browser
and see what it does (I would actually be interested to find out that it
does something different on your machine).
<?php
$firstDate = "19991031";
echo "<B>First Date:</B> " . $firstDate . "<BR>\n";;
$year = substr($firstDate, 0, 4);
$month = substr($firstDate, 4, 2);
$day = substr($firstDate, -2);
$firstTime = mktime(0, 0, 0, $month, $day, $year);
echo "<B>First Time:</B> " . $firstTime . "<BR>\n";
echo "adding 86400 seconds...<BR>\n";
$secondTime = $firstTime + 86400;
echo "<B>Second Time:</B> " . $secondTime . "<BR>\n";
echo "<B>Second Date:</B> " . date("Ymd", $secondTime);
?>
I've seen no other option at this point then to double check the value
I get, making sure it is not equal to the last date stamp, and make
changes manually.
Am I missing something so obvious that I haven't looked for it, or have
I really hit some mysterious wall in PHP?
Many thanks for any help!
Nick