php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53417 strtotime does not handle MySQL Fuzzy Dates Correctly
Submitted: 2010-11-26 16:03 UTC Modified: 2010-11-26 16:32 UTC
From: trevor dot white at ge dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.3.1RC1 OS: Redhat
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: trevor dot white at ge dot com
New email:
PHP Version: OS:

 

 [2010-11-26 16:03 UTC] trevor dot white at ge dot com
Description:
------------
The function strtotime doesn't handle MySQL fuzzy dates correctly, in MySQL it is possible to store fuzzy dates replacing the unknown date figure with 00, for example.
2010-10-00 00:00:00
which is UK format Y-m-d

If you pass this script to strtotime and wrap the date function around it:

date('M y', (strtotime($monrow['eventdate'])));

PHP will return Oct 10, which is a month out as it should return Nov 10.

Workaround is to use str_replace to change the 00 to 01 when processing.

Test script:
---------------
date('M y', (strtotime("2010-10-00 00:00:00")));

Expected result:
----------------
Nov 10 (Month as specified)

Actual result:
--------------
Oct 10 (Previous Month)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-26 16:17 UTC] derick@php.net
-Status: Open +Status: Bogus
 [2010-11-26 16:17 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 how it is supposed to be. Day 0 is an underflow, so the date gets auto corrected to 2010-09-30 (from 2010-10-00). (You seem to be confusing 10 with November in your report btw).
 [2010-11-26 16:32 UTC] trevor dot white at ge dot com
Sorry yes my mistake, I meant to put 2010-11-00 00:00:00 in my example.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 06:01:34 2024 UTC