note 89184 deleted from function.strtotime by derick
| From: | derick@php.net | Date: | Sun, 14 Dec 2014 11:35:09 +0000 |
| Subject: | note 89184 deleted from function.strtotime by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-201168@lists.php.net to get a copy of this message | ||
Note Submitter: bbutts at stormcode dot net
----
After looking around I couldn't find any code that would properly and simply compute the last
day of the month. +1 month will not work ex. 1 month after February 28th is March 3rd.
This line of code returns the last day of the current month:
<?php
echo 'Last day of the month: ' . date('m/d/y h:i a',(strtotime('next
month',strtotime(date('m/01/y'))) - 1));
?>
It uses the first of the current month, gets the first of the next month, then subtracts 1 second to
give you 11:59pm on the last day of the current month.
Hope this helps someone.