note 88676 added to function.strtotime

From: Date: Tue, 03 Feb 2009 15:30:58 +0000
Subject: note 88676 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-150147@lists.php.net to get a copy of this message
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'! ---- Server IP: 69.147.83.197 Probable Submitter: 87.159.109.104 ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- https://master.php.net/note/edit/88676 Del: integrated -- https://master.php.net/note/delete/88676/integrated Del: useless -- https://master.php.net/note/delete/88676/useless Del: bad code -- https://master.php.net/note/delete/88676/bad+code Del: spam -- https://master.php.net/note/delete/88676/spam Del: non-english -- https://master.php.net/note/delete/88676/non-english Del: in docs -- https://master.php.net/note/delete/88676/in+docs Del: other reasons-- https://master.php.net/note/delete/88676 Reject -- https://master.php.net/note/reject/88676 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#150147) next »