php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37514 strtotime doesn't assume year correctly
Submitted: 2006-05-18 22:43 UTC Modified: 2006-05-19 14:53 UTC
From: pcavit at gmail dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.1.4 OS: FreeBSD 6
Private report: No CVE-ID: None
 [2006-05-18 22:43 UTC] pcavit at gmail dot com
Description:
------------
When using strtotime to parse dates if an 'am' or 'pm' is added without specifying a year false will be returned.

Reproduce code:
---------------
echo date('r', strtotime('May 18th 5:05'));
echo date('r', strtotime('May 18th 5:05pm'));
echo date('r', strtotime('May 18th 5:05 pm'));
echo date('r', strtotime('May 18th 5:05am'));
echo date('r', strtotime('May 18th 5:05 am'));
echo date('r', strtotime('May 18th 2006 5:05pm'));



Expected result:
----------------
Thu, 18 May 2006 05:05:00 -0700
Thu, 18 May 2006 17:05:00 -0700
Thu, 18 May 2006 17:05:00 -0700
Thu, 18 May 2006 05:05:00 -0700
Thu, 18 May 2006 05:05:00 -0700
Thu, 18 May 2006 17:05:00 -0700

Actual result:
--------------
Thu, 18 May 2006 05:05:00 -0700
Wed, 31 Dec 1969 16:00:00 -0800
Wed, 31 Dec 1969 16:00:00 -0800
Wed, 31 Dec 1969 16:00:00 -0800
Wed, 31 Dec 1969 16:00:00 -0800
Thu, 18 May 2006 17:05:00 -0700

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-19 01:59 UTC] judas dot iscariote at gmail dot com
This seems to be the expected behaviour, as it returns -1 on PHP4.4.3-dev,4.3,6 , and false in PHP 5.2-dev.however im not sure it is the "desired" behaviour..;-)
 [2006-05-19 07:12 UTC] derick@php.net
Definitely not a bug... in PHP 4 not even the first one works actually. That doesn't mean we can't have a look if we can add support for this format though.
 [2006-05-19 14:53 UTC] derick@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 09:01:32 2024 UTC