php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #15210 strtotime() doesn't work with ordinal suffixes
Submitted: 2002-01-24 13:35 UTC Modified: 2002-01-24 17:25 UTC
From: basil dot hussain at kodakweddings dot com Assigned: markonen (profile)
Status: Closed Package: Feature/Change Request
PHP Version: 4.0.5 OS: Linux 2.2.16enterprise
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: basil dot hussain at kodakweddings dot com
New email:
PHP Version: OS:

 

 [2002-01-24 13:35 UTC] basil dot hussain at kodakweddings dot com
PHP does not correctly parse ordinal date suffixes in the strtotime() function. For example:

<?php
echo strtotime("10th August 2002");
echo strtotime("22nd January 1998");
echo strtotime("November 3rd 1980");
?>

They will all fail, returning -1.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-01-24 13:44 UTC] derick@php.net
Not a bug (it is not supposed to work), making it a feature request.

Derick
 [2002-01-24 14:16 UTC] markonen@php.net
Could someone sanity check this patch?

diff -c -r1.29 parsedate.y
*** parsedate.y 2 Dec 2001 11:35:28 -0000       1.29
--- parsedate.y 24 Jan 2002 19:14:52 -0000
***************
*** 721,726 ****
--- 721,740 ----
    int i;
    int abbrev;
  
+   /* Strip ordinal suffixes from dates */
+   if ((strlen (buff) == 3 || strlen (buff) == 4) && 
ISDIGIT(buff[0])) {
+       i = strlen (buff) - 2;
+       if (buff[i] == 's' && buff[i+1] == 't') {
+         buff[i] = '\0';
+       } else if (buff[i] == 'n' && buff[i+1] == 'd') {
+         buff[i] = '\0';
+       } else if (buff[i] == 'r' && buff[i+1] == 'd') {
+         buff[i] = '\0';
+       } else if (buff[i] == 't' && buff[i+1] == 'h') {
+         buff[i] = '\0';
+       }
+   }
+   
    /* Make it lowercase. */
    for (p = buff; *p; p++)
      if (ISUPPER ((unsigned char) *p))

 [2002-01-24 14:32 UTC] markonen@php.net
Nah, wrong approach. Assigning to myself.
 [2002-01-24 17:25 UTC] markonen@php.net
Feature added in CVS.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue May 06 12:01:29 2025 UTC