note 128577 added to function.strtotime
| From: | info at pipasjourney dot com | Date: | Wed, 31 May 2023 22:02:57 +0000 |
| Subject: | note 128577 added to function.strtotime | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-220533@lists.php.net to get a copy of this message | ||
Be aware of this: 1 month before the 31st day, it will return the same month:
<?php
echo date('m', strtotime('2023-05-30 -1 month')) ; //returns 04
echo date('m', strtotime('2023-05-31 -1 month')) ; //returns 05, not 04
?>
So, don't use this to operate on the month of the result.
A better way to know what month was the previous month would be:
<?php
//considering today is 2023-05-31...
$firstOfThisMonth = date('Y-m') . '-01'; //returns 2023-05-01
echo date('m', strtotime($firstOfThisMonth . ' -1 month')) ; //returns 04
?>
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.13.130 (proxied: 190.193.86.188)
----
Manual Page -- https://php.net/manual/en/function.strtotime.php
Edit -- https://main.php.net/note/edit/128577
Del: integrated -- https://main.php.net/note/delete/128577/integrated
Del: useless -- https://main.php.net/note/delete/128577/useless
Del: bad code -- https://main.php.net/note/delete/128577/bad+code
Del: spam -- https://main.php.net/note/delete/128577/spam
Del: non-english -- https://main.php.net/note/delete/128577/non-english
Del: in docs -- https://main.php.net/note/delete/128577/in+docs
Del: other reasons-- https://main.php.net/note/delete/128577
Reject -- https://main.php.net/note/reject/128577
Search -- https://main.php.net/manage/user-notes.php