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
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: 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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 05:01:33 2025 UTC