note 93898 deleted from function.strtotime by crell
| From: | crell@php.net | Date: | Thu, 30 Jun 2022 20:58:54 +0000 |
| Subject: | note 93898 deleted from function.strtotime by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218815@lists.php.net to get a copy of this message | ||
Note Submitter: Anonymous
----
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
?>