note 60276 deleted from function.strtotime by derick
| From: | derick@php.net | Date: | Sun, 15 Jul 2007 12:44:07 +0000 |
| Subject: | note 60276 deleted from function.strtotime by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-128563@lists.php.net to get a copy of this message | ||
Note Submitter: dean at earlsoft dot co dot uk
----
I have recently had to handle parsing date strings without a year, which broke when the year rolled
over.
Assuming the dates will always be in the past, you can use this to fall back to the previous year if
the date is too far in the future:
<?php
$data = strtotime("26 dec");
print date("r", $data) . "\n";
if ($data > strtotime("+1 week")) {
print "Too far in the future\n";
$data = strtotime("-1 year", $data);
}
print date("r", $data) . "\n";
?>
This outputs:
Tue, 26 Dec 2006 00:00:00 +0000
Too far in the future
Mon, 26 Dec 2005 00:00:00 +0000