note 88867 deleted from function.strtotime by derick

From: Date: Sun, 14 Dec 2014 11:36:19 +0000
Subject: note 88867 deleted from function.strtotime by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-201171@lists.php.net to get a copy of this message
Note Submitter: Zoe Blade ---- Here's a revised version of [code I originally wrote on 21-JAN-09]. You can work out the number of days left in the month or year like this. [This version] also works with arbitrary dates given to it rather than only working with the current date: <?php function days_left_in_month($isoDate) { $date = explode('-', $isoDate); $date[1]++; $date[1] = str_pad($date[1], 2, '0', STR_PAD_LEFT); if ($date[1] == '13') { $date[0]++; $date[1] = '01'; } $date[2] = '01'; $isoDateNextMonth = implode('-', $date); return ceil((strtotime($isoDateNextMonth) - strtotime($isoDate)) / 86400); } echo days_left_in_month('2009-01-31'); // Much better ?> [EDIT BY danbrown AT php DOT net: Contains bugfixes by (akniep AT rayo DOT info) on 03-FEB-09 and the original author.]

« previous php.notes (#201171) next »