php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #52123 strtotim() returns date for one year ago
Submitted: 2010-06-19 11:22 UTC Modified: 2010-06-19 17:13 UTC
From: alipendashteh at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.3.2 OS: Windows
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: alipendashteh at gmail dot com
New email:
PHP Version: OS:

 

 [2010-06-19 11:22 UTC] alipendashteh at gmail dot com
Description:
------------
Hi,
strtotime returns wrong date (one year ago) with some formats like:
2011, February 8


Test script:
---------------
echo (date('Y-m-d', strtotime("2011, February 8")));

Expected result:
----------------
2011-02-08

Actual result:
--------------
2010-02-08

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-06-19 11:41 UTC] derick@php.net
-Status: Open +Status: Bogus -Package: *Data Exchange functions +Package: Date/time related
 [2010-06-19 11:41 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is not a bug. 2011 is seen as time instead:

php -r 'var_dump(date_parse("2011, February 8"));'
array(12) {
  ["year"]=>
  bool(false)
  ["month"]=>
  int(2)
  ["day"]=>
  int(8)
  ["hour"]=>
  int(20)
  ["minute"]=>
  int(11)
  ["second"]=>
  int(0)
  ["fraction"]=>
  bool(false)
  ["warning_count"]=>
  int(0)
  ["warnings"]=>
  array(0) {
  }
  ["error_count"]=>
  int(0)
  ["errors"]=>
  array(0) {
  }
  ["is_localtime"]=>
  bool(false)
}
 [2010-06-19 12:59 UTC] alipendashteh at gmail dot com
you right; this is not a bug.
but i think the "Y, F j" is much more common than "Hi, F j".
and many application like Drupal use "Y, F j" as a default date format. so parsing date as "Hi, F j" rather than "Y, F j" would cause confiusing errors in applications.
I suggest replace the priorities of two format mentioned.
 [2010-06-19 13:03 UTC] degeberg@php.net
You already have DateTime::createFromFormat() if you wish to parse other formats.
 [2010-06-19 13:10 UTC] alipendashteh at gmail dot com
Yes; but I meant the default behavior of strtotime() is not appropriate now.
and i think it is absolutely better that something like "2011, February 8" parses as "Y, F j" instead of "Hi, F j".
 [2010-06-19 17:13 UTC] derick@php.net
Perhaps, but we can't just change how the parser works. Others might perhaps rely on this.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 20:01:35 2025 UTC