|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79006 Function strtotime Misbehaves with Years
Submitted: 2019-12-20 12:00 UTC Modified: 2019-12-21 06:56 UTC
From: lesichkovm at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 7.4.1 OS:
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: lesichkovm at gmail dot com
New email:
PHP Version: OS:


 [2019-12-20 12:00 UTC] lesichkovm at gmail dot com
String to time does not work correct when a year is provided.


echo date('Y-m-d', strtotime('2016'));



Test script:
echo date('Y-m-d', strtotime('2016'));

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-12-20 12:15 UTC]
-Status: Open +Status: Not a bug
 [2019-12-20 12:15 UTC]
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.

 [2019-12-21 06:56 UTC] lesichkovm at gmail dot com
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:

  $year = $year.'-01-01';

echo date('Y-m-d', strtotime($year));

I don't see how this benefits anyone
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jul 18 18:01:30 2024 UTC