note 126108 added to datetime.modify
| From: | wes at anonymous dot com | Date: | Tue, 25 May 2021 21:12:39 +0000 |
| Subject: | note 126108 added to datetime.modify | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-216427@lists.php.net to get a copy of this message | ||
Beware, the modify function does not treat .5 as a half minute!
echo "start with: $str\n";
$datetimeObj = new DateTime($str);
$datetimeObj->modify('1 minutes');
echo "add 1 min: ".$datetimeObj->format('m/d/Y h:i:s
A')."\n";
$datetimeObj = new DateTime($str);
$datetimeObj->modify('.5 minutes');
echo "add .5 min: ".$datetimeObj->format('m/d/Y h:i:s
A')."\n";
$datetimeObj->modify('.53453531 minutes');
echo "add .53453531 min: ".$datetimeObj->format('m/d/Y h:i:s
A')."\n";
start with: 05/25/2021 02:53:40 PM
add 1 min: 05/25/2021 02:54:40 PM
add .5 min: 05/25/2021 02:58:40 PM
add .53453531 min: 01/12/2123 03:09:40 AM
.5 minutes actually ends up adding 5 minutes, not a half minute, and .53453531 adds 53453531
minutes.
So, if you have a function that accepts a number for adding minutes to a datetime, you have to check
for < 1 and > -1, and then possibly convert that to seconds and do a seconds modification.
----
Server IP: 45.112.84.4
Probable Submitter: 45.112.85.242 (proxied: 173.89.21.234)
----
Manual Page -- https://php.net/manual/en/datetime.modify.php
Edit -- https://main.php.net/note/edit/126108
Del: integrated -- https://main.php.net/note/delete/126108/integrated
Del: useless -- https://main.php.net/note/delete/126108/useless
Del: bad code -- https://main.php.net/note/delete/126108/bad+code
Del: spam -- https://main.php.net/note/delete/126108/spam
Del: non-english -- https://main.php.net/note/delete/126108/non-english
Del: in docs -- https://main.php.net/note/delete/126108/in+docs
Del: other reasons-- https://main.php.net/note/delete/126108
Reject -- https://main.php.net/note/reject/126108
Search -- https://main.php.net/manage/user-notes.php