note 100525 deleted from function.strtotime by danbrown
| From: | danbrown@php.net | Date: | Thu, 21 Oct 2010 13:24:23 +0000 |
| Subject: | note 100525 deleted from function.strtotime by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173344@lists.php.net to get a copy of this message | ||
Note Submitter: Zoe Blade
----
A much better way to work out the days left in the month:
// Gets the number of days left in the month. ISO 2014 format date in, int out.
function getDaysLeftInMonth($date = null, $includingToday = true) {
if ($date == null) {
$date = date('Y-m-d');
}
$currentTime = strtotime($date);
$futureTime = strtotime(date('Y-m-01', strtotime("{$date} + 1 month")));
$daysLeft = round(($futureTime - $currentTime) / 86400); // 60 seconds * 60 minutes * 24 hours =
86400 seconds in a day
if ($includingToday == true) {
return $daysLeft;
} else {
return $daysLeft - 1;
}
}