php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69408 Date strings consisting of year > 1999 not properly parsed
Submitted: 2015-04-09 15:38 UTC Modified: 2015-04-09 18:06 UTC
From: jkronika at gridlined dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.5.23 OS: Ubuntu
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jkronika at gridlined dot com
New email:
PHP Version: OS:

 

 [2015-04-09 15:38 UTC] jkronika at gridlined dot com
Description:
------------
When parsing strings containing only a year, it appears that certain ranges of years do not get parsed appropriately. This is a cause, at least in my case, of very difficult to debug errors.

Test script:
---------------
echo var_export(date_parse('1999'), true)."\n\n";
echo var_export(date_parse('2001'), true);

Expected result:
----------------
array (
  'year' => 1999,
  'month' => false,
  'day' => false,
  'hour' => false,
  'minute' => false,
  'second' => false,
  ...
)

array (
  'year' => 2001,
  'month' => false,
  'day' => false,
  'hour' => false,
  'minute' => false,
  'second' => false,
  ...
)

Actual result:
--------------
array (
  'year' => 1999,
  'month' => false,
  'day' => false,
  'hour' => false,
  'minute' => false,
  'second' => false,
  ...
)

array (
  'year' => false,
  'month' => false,
  'day' => false,
  'hour' => 20,
  'minute' => 1,
  'second' => 0,
  ...
)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-04-09 18:06 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2015-04-09 18:06 UTC] requinix@php.net
date_parse() follows the rules for strtotime(), which prefers parsing times over dates. 2000 is a valid time format (HHMM) but 1999 isn't so it's interpreted as a year.

Use date_parse_from_format() instead.
http://3v4l.org/QvVoR
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 12:00:01 2026 UTC