note 93898 added to function.strtotime

From: Date: Mon, 05 Oct 2009 22:47:53 +0000
Subject: note 93898 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-161383@lists.php.net to get a copy of this message
This function DOES NOT work from left-to-right as one would think. This function parses the string as a whole, then applies the intervals by size (year, month, ...). Take the following example: <?php $Date = strtotime('2011-02-22'); // February 22nd, 2011. 28 days in this month, 29 next year. echo date('n/j/Y', strtotime('+1 year, +7 days', $Date)); // add 1 year and 7 days. prints 2/29/2012 echo "<br />"; echo date('n/j/Y', strtotime('+7 days, +1 year', $Date)); // add 7 days and 1 year, but this also prints 2/29/2012 echo "<br />"; echo date('n/j/Y', strtotime('+1 year', strtotime('+7 days', $Date))); // this prints 3/1/2012, what the 2nd would do if it was left-to-right ?> ---- Server IP: 64.71.164.2 Probable Submitter: 209.248.93.38 ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- https://master.php.net/note/edit/93898 Del: integrated -- https://master.php.net/note/delete/93898/integrated Del: useless -- https://master.php.net/note/delete/93898/useless Del: bad code -- https://master.php.net/note/delete/93898/bad+code Del: spam -- https://master.php.net/note/delete/93898/spam Del: non-english -- https://master.php.net/note/delete/93898/non-english Del: in docs -- https://master.php.net/note/delete/93898/in+docs Del: other reasons-- https://master.php.net/note/delete/93898 Reject -- https://master.php.net/note/reject/93898 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#161383) next »