Bug #74275 [Opn->Nab]: strtotime()
| From: | cmb@php.net | Date: | Wed, 11 Nov 2020 13:15:56 +0000 |
| Subject: | Bug #74275 [Opn->Nab]: strtotime() | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-230265@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=74275&edit=1
ID: 74275
Updated by: cmb@php.net
Reported by: 252811115 at qq dot com
Summary: strtotime()
-Status: Open
+Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: window,linux
PHP Version: 7.1.3
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
> Hours in a 12-hour format time have the range 1-12.
That. Using
new DateTimeImmutable() also reveals the details:
Failed to parse time string (2020-11-110:45pm) at position 14 (p): The timezone could not be
found in the database
You should always check the return value of strtotime() (see also
example #2 on the doc page[1]).
[1] <https://www.php.net/strtotime>
Previous Comments:
------------------------------------------------------------------------
[2017-03-21 13:46:26] danack@php.net
To me, 00:59pm doesn't look like a valid time.
Hours in a 12-hour format time have the range 1-12.
Hours in a 24-hour format time have the range 0-23.
Obviously the behaviour of strtotime here is unexpected, but you've passed it something that
doesn't look like a valid timestamp, so there may not be a 'correct' behaviour for it
to follow.
------------------------------------------------------------------------
[2017-03-20 03:24:16] 252811115 at qq dot com
Description:
------------
if time is 00:00am to 00:59am
or 00:00pm to 00:59pm
strtotime()
Test script:
---------------
<?php
$time1 = '5:20am';
$time2 = '12:55pm';
$time3 = '9:55pm';
$time4 = '0:45pm';
$date = date('Y-m-d');
echo date('Y-m-d H:i:s',strtotime($date.$time1)).PHP_EOL;
echo date('Y-m-d H:i:s',strtotime($date.$time2)).PHP_EOL;
echo date('Y-m-d H:i:s',strtotime($date.$time3)).PHP_EOL;
echo date('Y-m-d H:i:s',strtotime($date.$time4)).PHP_EOL;
?>
2017-03-20 05:20:00
2017-03-20 12:55:00
2017-03-20 21:55:00
1970-01-01 08:00:00
Expected result:
----------------
<?php
$time1 = '5:20am';
$time2 = '12:55pm';
$time3 = '9:55pm';
$time4 = '0:45pm';
$date = date('Y-m-d');
echo date('Y-m-d H:i:s',strtotime($date.$time1)).PHP_EOL;
echo date('Y-m-d H:i:s',strtotime($date.$time2)).PHP_EOL;
echo date('Y-m-d H:i:s',strtotime($date.$time3)).PHP_EOL;
echo date('Y-m-d H:i:s',strtotime($date.$time4)).PHP_EOL;
?>
Actual result:
--------------
2017-03-20 05:20:00
2017-03-20 12:55:00
2017-03-20 21:55:00
1970-01-01 08:00:00
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=74275&edit=1