php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35414 strtotime() no longer works with ordinal suffix
Submitted: 2005-11-26 22:12 UTC Modified: 2006-01-05 11:00 UTC
From: km at somehowbythesea dot org dot uk Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.1.1 OS: Linux
Private report: No CVE-ID: None
 [2005-11-26 22:12 UTC] km at somehowbythesea dot org dot uk
Description:
------------
In PHP4.3, strtotime() will parse days of the month with and ordinal suffix, in the format "Sat 26th Nov 2005 18:18", however this is no longer possible in PHP5.1. The same string without the ordinal suffix ("Sat 26 Nov 2005 18:18") returns a timestamp as expected. 

I apologize in advance if this should now be listed as a feature request instead of a bug. In version 4.0.5 this problem was reported as a bug (#15210) when in fact the parsing of ordinals was not actually a feature at the time. Following that, the feature was added in CVS and was still working at version 4.3. 

Reproduce code:
---------------
<?
$tWithOrd = "Sat 26th Nov 2005 18:18";
$tWithoutOrd = "Sat 26 Nov 2005 18:18";

$UtimeWithOrd = strtotime($tWithOrd);
$UtimeWithoutOrd = strtotime($tWithoutOrd);

print("time string with ordinal suffix: $tWithOrd<br>");
print("time string without ordinal suffix: $tWithoutOrd<br><br>");

print("UNIX timestamp from time string with ordinal suffix: $UtimeWithOrd<br>");
print("UNIX timestamp from time string without ordinal suffix: $UtimeWithoutOrd<br><br>");
?>

Expected result:
----------------
Both variables $UtimeWithOrd and $UtimeWithoutOrd should contain a UNIX timestamp, printing it to screen with the last two lines.

Actual result:
--------------
Only the variable $UtimeWithoutOrd contains a timestamp. $UtimeWithOrd is empty and prints nothing.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-11-29 02:23 UTC] iliaa@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.


 [2006-01-05 07:45 UTC] km at somehowbythesea dot org dot uk
The strtotime function still fails to produce a UNIX timestamp from strings where the date - a number with it's ordinal suffix - precedes the month. 

For example, "Sat Nov 26th 2005 18:18" will produce a timestamp but "Sat 26th Nov 2005 18:18" will not.
 [2006-01-05 09:11 UTC] derick@php.net
Works fine:

derick@kossu:/dat/dev/php/php-5.1dev$ sapi/cli/php -v
PHP 5.1.2RC2-dev (cli) (built: Jan  4 2006 11:24:53) (DEBUG)
Copyright (c) 1997-2005 The PHP Group
Zend Engine v2.1.0, Copyright (c) 1998-2005 Zend Technologies

derick@kossu:/dat/dev/php/php-5.1dev$ sapi/cli/php -r 'var_dump(strtotime("Sat 26th Nov 2005 18:18"));'
int(1133025480)

derick@kossu:/dat/dev/php/php-5.1dev$ sapi/cli/php -r 'echo date(DATE_ISO8601, strtotime("Sat 26th Nov 2005 18:18")), "\n";'
2005-11-26T18:18:00+0100

 [2006-01-05 09:55 UTC] km at somehowbythesea dot org dot uk
My apologies, Derick. On 'var_dump(strtotime("Sat 26th Nov 2005 18:18"));' I'm getting bool(false). 'echo
date(DATE_ISO8601, strtotime("Sat 26th Nov 2005 18:18")), "\n";' gives 1969-12-31T19:00:00-0500. Does this imply my host has rebuilt PHP5.1.1 from the wrong source?

Thank you for your quick response to my previous update. I really appreciate it.
 [2006-01-05 10:13 UTC] sniper@php.net
Fixed in CVS does not mean that we somehow magically fixed all released sources..grab a snapshot from http://snaps.php.net/
 [2006-01-05 10:33 UTC] km at somehowbythesea dot org dot uk
I neither believe in nor asked any questions about fixing sources by magic.

I appreciate your time but not your sarcasm.
 [2006-01-05 10:53 UTC] derick@php.net
It's fixed in CVS, not in 5.1.1. You reported the bug in PHP 5.1.1, which we can not fix for you as it is released already. This fix is in PHp 5.1.2 (-dev), if you want to verify you need to try a snapshot. 
 [2006-01-05 11:00 UTC] km at somehowbythesea dot org dot uk
I understand. Thank you.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 02:01:28 2024 UTC