php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #63776 strtotime fails with 'at'
Submitted: 2012-12-14 22:53 UTC Modified: 2013-11-27 17:17 UTC
From: matthewcomp at hotmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.4.9 OS: Linux gator1111.hostgator.com 3.
Private report: No CVE-ID:
 [2012-12-14 22:53 UTC] matthewcomp at hotmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.strtotime
---

Does not work to read a date in the following format:
Nov 19, 2012 at 7:03 PM

Test script:
---------------
<?php

  $date = "Nov 19, 2012 at 7:03 PM";

  if (($timestamp = strtotime($date)) === false) {
    echo "The string ($date) is bogus";
  } else {
    echo "$date => " . date('l dS \o\f F Y h:i:s A', $timestamp);
  }

?>

Expected result:
----------------
Correctly parse the date, ignoring at, which can commonly appear in dates.

Actual result:
--------------
Completely unable to parse the date.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-15 04:22 UTC] sixd@php.net
-Summary: Fails With 'at' +Summary: strtotime fails With 'at'
 [2012-12-15 04:22 UTC] sixd@php.net
-Summary: strtotime fails With 'at' +Summary: strtotime fails with 'at'
 [2013-11-27 17:17 UTC] derick@php.net
-Status: Open +Status: Not a bug
 [2013-11-27 17:17 UTC] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

This is not a bug. strtotime() can not parse *everything* you throw at it. In this case it sees the extra text "at" as a timezone abbreviation. But as it does not know the abbreviation, it gives up. You can see what it does by using date_parse():

derick@whisky:/tmp $ php -r 'var_dump( date_parse( "Nov 19, 2012 at 7:03 PM" ) );'

array(13) {
  'year' =>
  int(2012)
  'month' =>
  int(11)
  'day' =>
  int(19)
  'hour' =>
  int(19)
  'minute' =>
  int(3)
  'second' =>
  int(0)
  'fraction' =>
  double(0)
  'warning_count' =>
  int(0)
  'warnings' =>
  array(0) {
  }
  'error_count' =>
  int(1)
  'errors' =>
  array(1) {
    [13] =>
    string(47) "The timezone could not be found in the database"
  }
  'is_localtime' =>
  bool(true)
  'zone_type' =>
  int(0)
}
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sat Apr 19 14:01:50 2014 UTC