note 79367 deleted from function.strtotime by danbrown
| From: | danbrown@php.net | Date: | Mon, 18 May 2009 02:22:31 +0000 |
| Subject: | note 79367 deleted from function.strtotime by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155648@lists.php.net to get a copy of this message | ||
Note Submitter: Hayley Watson
----
Beat's analysis fails to take into account the fact that when strtotime() subtracts three
months it really does subtract three months: 31 December minus three months is 31 September. And a
look at the calendar will show what "31 September" is really called.
In other words strtotime() is doing exactly what Beat claims in the following note mktime() does.
The reason why Beat's "workaround" works is because
mktime( 23, 59, 59, 1 - 3, 0, 2008 );
represents the 0th day of the -2nd month of 2008. That's 0 October 2007. And 0 October is 30
September.
Which is the reason Beat clearly discovered that using mktime( 23, 59, 59, 12 - 3, 31, 2007 ) to
represent 31 December 2007 turned out not to work.
mktime(23, 59, 59, 12, 31, 2007) == mktime(23, 59, 59, 1, 0, 2008) but
mktime(23, 59, 59, 12-3, 31, 2007) refers to "31 September 2007", --> "1 October
2007"; and
mktime(23, 59, 59, 1-3, 0, 2008) refers to "0 '-2' 2008" --> "0 October
2007" --> "30 September 2007".
Just because the date you're starting from happens to be the last day of the month, it
doesn't mean that subtracting a month will leave you at the last day of the previous month.