note 129409 added to datetime.modify
| From: | php_net@striderweb.com | Date: | Thu, 18 Apr 2024 17:24:55 +0000 |
| Subject: | note 129409 added to datetime.modify | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221292@lists.php.net to get a copy of this message | ||
You have to be a bit careful with variables here. If for example you want to add a variable amount
of minutes you might use
->modify("+$min"). This will not work out if
$min is a negative number, because modify will see the "+" and ignore the
"-". If $min` equals -10, modify in this example will add ten minutes, not
subtract!
What is happening is if the modify string has two operations, the first will be obeyed and later
ones will be ignored.
So "+-10 minutes" will add ten minutes, even though you might expect it to add the
negative number. Similarly "--10 minutes" will subtract ten minutes, despite the apparent
logic of subtracting a negative number.
----
Server IP: 45.112.84.4
Probable Submitter: 80.90.13.131 (proxied: 207.141.165.163)
----
Manual Page -- https://php.net/manual/en/datetime.modify.php
Edit -- https://main.php.net/note/edit/129409
Del: integrated -- https://main.php.net/note/delete/129409/integrated
Del: useless -- https://main.php.net/note/delete/129409/useless
Del: bad code -- https://main.php.net/note/delete/129409/bad+code
Del: spam -- https://main.php.net/note/delete/129409/spam
Del: non-english -- https://main.php.net/note/delete/129409/non-english
Del: in docs -- https://main.php.net/note/delete/129409/in+docs
Del: other reasons-- https://main.php.net/note/delete/129409
Reject -- https://main.php.net/note/reject/129409
Search -- https://main.php.net/manage/user-notes.php