php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42675 strtotime returns valid dates for invalid entries
Submitted: 2007-09-14 21:51 UTC Modified: 2007-12-08 15:35 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: amykhar at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.4 OS: Mac OS X
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: amykhar at gmail dot com
New email:
PHP Version: OS:

 

 [2007-09-14 21:51 UTC] amykhar at gmail dot com
Description:
------------
If I enter a date with a text month and an invalid day, it returns as valid.

Example, September 45, 1992 returns as valid.  It THINKS the date is October 5, 1992.

(The same is true for Sep 45, 1992).

What it seems to do is to get the year correctly, then take the last digit of the day and then add 1 to the month.



Reproduce code:
---------------
    	$cdate = strtotime("September 45, 1992");
    	if(!$cdate){
    		echo(-1);
    		exit;
    	}
        else{
             echo (date("M d Y",$cdate);
        }

Expected result:
----------------
It echo -1.

Actual result:
--------------
It prints out October 5, 1992

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-16 15:37 UTC] iliaa@php.net
That is expected behavior. Although I would assume rather just adding 1 
month to the date it would add 1 month + remaining # of days.

My expected return value would be: October 15, 1992
 [2007-09-17 15:10 UTC] amykhar at gmail dot com
If it is expected behavior, why does it behave differently for numeric 
dates?  03/345/2007 returns invalid, as I would expect it to.  It seems 
counterintuitive to have a function that is widely used to process user-
entered data doing anything other than validating that the date entered 
is an actual date.
 [2007-10-07 05:13 UTC] jazzattcs at yahoo dot com
I'm having the same problem. strtotime("February 31, 2007 18:45:00 GMT")should return FALSE but it just gets converted to March 3. I'm using PHP 5.2.1 running on Windows.
 [2007-12-08 15:35 UTC] derick@php.net
This is a feature, and it just returns Ilia's (and mine) expected date of:
Oct 15 1992

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 27 01:00:02 2025 UTC