note 98966 added to function.strtotime
| From: | jim dot leek at eng dot ox dot ac dot uk | Date: | Mon, 19 Jul 2010 11:20:32 +0000 |
| Subject: | note 98966 added to function.strtotime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-170964@lists.php.net to get a copy of this message | ||
Don't be tempted to use strtotime to compare dates:
e.g.
<?php
// Calculate the difference in days.
$date1 = strtotime(2010-10-10);
$date2 = strtotime(2011-12-01);
$daysDiff = ($date2 - $date1)/(24 * 60 * 60);
// Which is the latest?
if ($date2 > $date1) {
echo "$date2 is later than $date1";
}
?>
If you do, your code will be susceptible to the 2038 bug.
(This is because Unix timestamps cannot deal with dates before Fri, 13 Dec 1901 20:45:54 UTC and
after Tue, 19 Jan 2038 03:14:07 UTC).
Instead convert your dates to Julian dates, and compare those. (For example use the function
GregorianToJD which has been available since PHP4).
----
Server IP: 213.229.106.14
Probable Submitter: 163.1.222.66
----
Manual Page -- http://www.php.net/manual/en/function.strtotime.php
Edit -- https://master.php.net/note/edit/98966
Del: integrated -- https://master.php.net/note/delete/98966/integrated
Del: useless -- https://master.php.net/note/delete/98966/useless
Del: bad code -- https://master.php.net/note/delete/98966/bad+code
Del: spam -- https://master.php.net/note/delete/98966/spam
Del: non-english -- https://master.php.net/note/delete/98966/non-english
Del: in docs -- https://master.php.net/note/delete/98966/in+docs
Del: other reasons-- https://master.php.net/note/delete/98966
Reject -- https://master.php.net/note/reject/98966
Search -- https://master.php.net/manage/user-notes.php