php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45713 Function strtotime() always returns FALSE if year > 2037!!
Submitted: 2008-08-05 02:43 UTC Modified: 2008-08-05 22:40 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:2 (100.0%)
Same OS:2 (100.0%)
From: kris dot craig at gmail dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.2.6 OS: Windows
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: kris dot craig at gmail dot com
New email:
PHP Version: OS:

 

 [2008-08-05 02:43 UTC] kris dot craig at gmail dot com
Description:
------------
Any time I enter a date (any format) into strtotime that contains a year later than 2037, the function returns FALSE every time.  If I change the year to 2037 or earler, without changing anything else, it works every time.  I have not been able to find any documentation or other information to explain this phenomenon.

Pertinent server/module/etc information can be found here:  http://www.kriscraig.com/phpinfo.php

Reproduce code:
---------------
/* This could not be simpler.... */
print strtotime( "2012-05-06" );  //1336287600 (works)
print strtotime( "12 May 2037" );  //2125724400 (works)
print strtotime( "12 May 2038" );  // (doesn't work!)
print strtotime( "2500-05-06" );  // (doesn't work!)


Expected result:
----------------
They should all return a valid timestamp.  FALSE should only be returned if it fails, which is not supposed to happen simply because the year being input is greater than 2037!


Actual result:
--------------
It returns FALSE.  Nothing.  Nada.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-05 06:48 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

Please read *all* the documentation at:
http://no.php.net/strtotime

Alternatively, use the OO date/time functionality:
http://no.php.net/manual/en/function.date-create.php
 [2008-08-05 19:49 UTC] kris dot craig at gmail dot com
Excuse me, but this is a bug, and it is NOT bogus.  I have consulted the documentation.  Unless you can provide some sort of solution to this problem or at least explain why you don't think it's a bug that PHP won't handle any year past 2037, then I will re-post this bug in hopes that the next person who looks it over will actually give it some deliberative thought before dismissing it.
 [2008-08-05 19:59 UTC] kris dot craig at gmail dot com
It should be noted that this bug has been reported numerous times over the last few years (though not recently), and this is the first time anyone ever responded by trying to claim that it's somehow bogus.
 [2008-08-05 20:24 UTC] derick@php.net
Read it again, perhaps you then notice this one:

"Note: The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 GMT to Tue, 19 Jan 2038 03:14:07 GMT. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.)"

Of course, on a 64-bit platform this is not an issue.
 [2008-08-05 20:54 UTC] kris dot craig at gmail dot com
You assume I don't already know that??  I told you, I've already researched this thoroughly.  Yes, I am aware that this is the CAUSE of the bug, but it doesn't mean that it isn't still a bug nonetheless, it simply means that it'll be very difficult to solve.  It is not bogus, and it was not appropriate to classify it as such.

Instead, we should be talking about finding creative ways to solve the problem, other than just telling people to go out and get a 64-bit system.  Perhaps try a different data type?  Or return it as a string value if it goes beyond that size?  These are just random ideas off the top of my head, of course, but my point is that there should be at least some deliberative effort put in to fixing this (or at least *discussing* ways to fix it) before simply dismissing it as "bogus" and insulting anyone who researches the issue and posts it as a bug report.
 [2008-08-05 21:13 UTC] derick@php.net
I already wrote about the alternative in my first comment, but because reading is obviously hard for you, I'll paste you the URL again:

http://no.php.net/date_create

 [2008-08-05 21:21 UTC] kris dot craig at gmail dot com
Perhaps you shouldn't be responding to these bug postings?  You seem to respond only by hurling childish insults, this time belittling my intelligence by alleging that I don't know how to read.  I did read your posts, including the suggestion about using date_create.  But that is a workaround, not a solution.  A solution would be fixing strtotime() and other similar functions so that they can accept a year past 2037-- some have said it's like "Unix's Y2K"; i.e. we're going to have to address it eventually, so why wait 'till the last minute?

At very least, we should update the documentation on that function to clearly outline this limitation, including the reasons behind it, and a suggested workaround.  However, I think that should be the "Plan B" resolution, in the event that we can't find something better.  But we won't if you keep reducing the level of this dialogue by including childish, non-constructive, unprofessional insults in your responses.
 [2008-08-05 22:08 UTC] scottmac@php.net
Derick has given you a solution, use the new DateTime class.

$date = new DateTime("12 May 2038"); echo $date->format("U");
 [2008-08-05 22:40 UTC] kris dot craig at gmail dot com
No, he hasn't.  That isn't a solution.  It's a workaround.  I already said that in my last post.

If this is the best we can do, then strtotime() should be depreciated, and the PHP documentation should point all users to the new DateTime class.

Either way, this isn't a solution as it stands now.  At very least the documentation for strtotime() needs some serious updating.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jun 27 02:01:29 2024 UTC