note 97710 deleted from function.strtotime by danbrown
| From: | danbrown@php.net | Date: | Tue, 04 May 2010 14:13:52 +0000 |
| Subject: | note 97710 deleted from function.strtotime by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-168922@lists.php.net to get a copy of this message | ||
Note Submitter: regady at freemail dot hu
----
To create the last day of the previous month (in PHP 5.2.10).
For example:
If today is 2010-03-15 and I want to get 2010-02-28!
<?php
// This will not make the correct date
echo date("Y-m-d", strtotime("last day last month")); // 2010-02-14
// This trick will give this month's 0th day, namely prev month's last day
echo date("Y-m-d", strtotime( (substr(date("Y-m-d"), 0, 7) . "-00")
)); // 2010-02-28
?>
You can change to any other specified date:
<?php
echo date("Y-m-d", strtotime( (substr(date("Y-m-d", $timestamp), 0, 7) .
"-00") ));
?>