Bug #79006 [Opn->Nab]: Function strtotime Misbehaves with Years
Edit report at https://bugs.php.net/bug.php?id=79006&edit=1
ID: 79006
Updated by: salathe@php.net
Reported by: lesichkovm at gmail dot com
Summary: Function strtotime Misbehaves with Years
-Status: Open
+Status: Not a bug
Type: Bug
Package: Date/time related
PHP Version: 7.4.1
Block user comment: N
Private report: N
New Comment:
The string "2016" is interpreted as a two-digit hour and
two-digit minutes time, rather than a four-digit year.
To demonstrate this:
echo date('H:i', strtotime('2016')); // 20:16
This case is explicitly mentioned in the "Date Formats" manual page [1]:
> Note: The "Year (and just the year)" format only works if a time
> string has already been found -- otherwise this format is
> recognised as HH MM.
[1] https://www.php.net/manual/en/datetime.formats.date.php
Previous Comments:
------------------------------------------------------------------------
[2019-12-20 12:00:00] lesichkovm at gmail dot com
Description:
------------
String to time does not work correct when a year is provided.
Example:
echo date('Y-m-d', strtotime('2016'));
Returns:
2019-12-20
Test script:
---------------
<?php
echo date('Y-m-d', strtotime('2016'));
Expected result:
----------------
2016-01-01
Actual result:
--------------
2019-12-20
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79006&edit=1
Thread (3 messages)