note 127881 added to datetime.formats.relative
| From: | frederic dot royet at logipro dot com | Date: | Mon, 31 Oct 2022 07:07:01 +0000 |
| Subject: | note 127881 added to datetime.formats.relative | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-219835@lists.php.net to get a copy of this message | ||
Be careful when using "-1 month" the last days of a month.
For instance the 31th of october: result won't be in september but in october !
Please, consider this:
<?php
print_r(new DateTime("now"));
print_r(new DateTime("-1 month"));
print_r(new DateTime("-2 months"));
?>
Result is:
DateTime Object
(
[date] => 2022-10-31 07:42:32.968925
[timezone_type] => 3
[timezone] => Europe/Paris
)
DateTime Object
(
[date] => 2022-10-01 07:42:32.969344
[timezone_type] => 3
[timezone] => Europe/Paris
)
DateTime Object
(
[date] => 2022-08-31 07:42:32.969349
[timezone_type] => 3
[timezone] => Europe/Paris
)
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.159.161 (proxied: 2a01:e0a:322:5ec0:fdb9:579e:9102:4a57)
----
Manual Page -- https://php.net/manual/en/datetime.formats.relative.php
Edit -- https://main.php.net/note/edit/127881
Del: integrated -- https://main.php.net/note/delete/127881/integrated
Del: useless -- https://main.php.net/note/delete/127881/useless
Del: bad code -- https://main.php.net/note/delete/127881/bad+code
Del: spam -- https://main.php.net/note/delete/127881/spam
Del: non-english -- https://main.php.net/note/delete/127881/non-english
Del: in docs -- https://main.php.net/note/delete/127881/in+docs
Del: other reasons-- https://main.php.net/note/delete/127881
Reject -- https://main.php.net/note/reject/127881
Search -- https://main.php.net/manage/user-notes.php