Bug #79006 [Nab]: Function strtotime Misbehaves with Years

From: Date: Sat, 21 Dec 2019 06:56:03 +0000
Subject: Bug #79006 [Nab]: Function strtotime Misbehaves with Years
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224458@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79006&edit=1 ID: 79006 User updated by: lesichkovm at gmail dot com Reported by: lesichkovm at gmail dot com Summary: Function strtotime Misbehaves with Years Status: Not a bug Type: Bug Package: Date/time related PHP Version: 7.4.1 Block user comment: N Private report: N New Comment: This definitely does not make sense from any perspective. I have not seen anyone use hour:minute time format without : as in 20:19. But literally everyone uses 2019 as represenation of years. There is no other use case for 4 numbers but to be a year. This should be revisited. Now to get the correct year I have to do somersaults like: if(strlen($year)==4){ $year = $year.'-01-01'; } echo date('Y-m-d', strtotime($year)); I don't see how this benefits anyone Previous Comments: ------------------------------------------------------------------------ [2019-12-20 12:15:29] salathe@php.net 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 ------------------------------------------------------------------------ [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

« previous php.bugs (#224458) next »