|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2004-06-01 07:49 UTC] fr33k at techie dot com
Description:
------------
When strtotime encounters certain intervals while using a zero "now" time as the second argument, it fails. Some intervals fail, others work fine. All worked fine with a non-zero "now" date. I was using this as a convenient way to translate intervals like "+1 Week" into seconds.
0+1 Day: 86400
0+2 Days: 172800
+3 Days: 1086327304
104022382+3 Days: 104281582
0+3 Days: -1
+332 Days: 1114752904
0+332 Days: -1
0+1 Week: -1
0+4 Weeks: -1
0+1 Month: 2678400
0+3 Months: 7776000
0+1 Year: 31536000
0+4 Years: 126230400
Reproduce code:
---------------
print "0+2 Days: ".strtotime('+2 Days',0)."\n";
print "+3 Days: ".strtotime('+3 Days')."\n";
print "104022382+3 Days: ".strtotime('+3 Days',104022382)."\n";
print "0+3 Days: ".strtotime('+3 Days',0)."\n";
print "+332 Days: ".strtotime('+332 Days')."\n";
print "0+332 Days: ".strtotime('+332 Days',0)."\n";
print "0+1 Week: ".strtotime('+1 Week',0)."\n";
print "0+4 Weeks: ".strtotime('+4 Weeks',0)."\n";
print "0+3 Months: ".strtotime('+3 Months',0)."\n";
print "0+1 Year: ".strtotime('+1 Year',0)."\n";
Expected result:
----------------
0+2 Days: 172800
+3 Days: 1086327494
104022382+3 Days: 104281582
0+3 Days: 259200
+332 Days: 1114753094
0+332 Days: 28684800
0+1 Week: 604800
0+4 Weeks: 2419200
0+3 Months: 7776000
0+1 Year: 31536000
Actual result:
--------------
0+2 Days: 172800
+3 Days: 1086327494
104022382+3 Days: 104281582
0+3 Days: -1
+332 Days: 1114753094
0+332 Days: -1
0+1 Week: -1
0+4 Weeks: -1
0+3 Months: 7776000
0+1 Year: 31536000
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 10:00:01 2025 UTC |
I just experienced some weirdness involving strtotime, don't know if it's the same as this bug, since I'm not using zero base time. The following code: <?php print date("d-m-Y H:i:s", strtotime("+30 minutes", time())); ?> gives me, in php4, the correct 30 minutes extra added to current time, eg: 18-07-2004 18:45:21 (when now is 18:15:21) BUT in php5.0.0, the 30 minutes are added to 00:00:00 at todays date, eg: 18-07-2004 00:30:00, which is of course wrong. Reproduced on both mandrake and debian installations of php5 in either cli(mdk)/cgi(deb).I am using PHP 5.2.6 on Windows XP personal production server with Apache/2.0.63 (Win32) PHP/5.2.6 and mySQL Server 5.1.59. I am encountering a problem with strtotime() function that returns FALSE on certain date strings. For example strtotime("02-03-2009") returns 1235980800 where strtotome("03-25-2009") returns FALSE. It appears that it doesn't really matter what the date strings are that make it fail, for instance 05-07-2009 returns 1246777200 and 05-01-2009 returns 1231142400 however 05-28-2011 returns FALSE as does 05-31-2011 Any suggestions how to overcome this behavior? Gregg