note 60276 added to function.strtotime

From: Date: Sun, 01 Jan 2006 20:40:49 +0000
Subject: note 60276 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-101084@lists.php.net to get a copy of this message
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 ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+60276 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60276&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60276&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60276&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60276&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60276&report=yes&reason=non-english Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60276&report=yes&reason=already+in+docs Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60276&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+60276&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#101084) next »