note 88676 deleted from function.strtotime by danbrown
| From: | danbrown@php.net | Date: | Wed, 11 Feb 2009 16:45:02 +0000 |
| Subject: | note 88676 deleted from function.strtotime by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-150495@lists.php.net to get a copy of this message | ||
Note Submitter: akniep at rayo dot info
----
I just happened to see the very last note (Zoe Blade, 21-Jan-2009 12:25) before this and I want to
add that the code will NOT always do as Zoe Blade says it would.
====================
Counter-example:
<?php
$test_date = strtotime( '2009-01-31' );
$daysLeftInMonth = ceil((strtotime(date('Y-m-01', strtotime('next month'))) -
$test_date) / 86400);
// will output 29, but not 1!
echo $daysLeftInMonth;
?>
Explanation: If you execute Zoe Blade's code on January 31st it will return 29 days and not (as
correct) 1 day.
====================
The reason for this is that strtotime evaluates '2009-01-31 +1 month' to the timestamp of
'2009-03-03'!
This behaviour is different to other implementations like for example MySQL where DATE_ADD(
'2009-01-31', INTERVAL 1 MONTH ) will return '2009-02-28'!