note 89184 modified in function.strtotime by danbrown
| From: | danbrown@php.net | Date: | Wed, 25 Feb 2009 18:47:18 +0000 |
| Subject: | note 89184 modified in function.strtotime by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-151128@lists.php.net to get a copy of this message | ||
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.
--was--
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:
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.
http://php.net/manual/en/function.strtotime.php