php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28599 strtotime fails with certain intervals & zero base time
Submitted: 2004-06-01 07:49 UTC Modified: 2004-11-15 17:31 UTC
Votes:2
Avg. Score:5.0 ± 0.0
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: fr33k at techie dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 4.3.5 OS: Debian
Private report: No CVE-ID: None
 [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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-06-01 07:53 UTC] fr33k at techie dot com
Sorry, pasted the "actual result" in the description.
 [2004-06-01 08:13 UTC] derick@php.net
Works fine for me. Which glibc do you have on your system? I've 2.3.2:

derick@kossu:~$ dpkg -l libc6
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name           Version        Description
+++-==============-==============-============================================
ii  libc6          2.3.2.ds1-12   GNU C Library: Shared libraries and Timezone

 [2004-06-03 02:24 UTC] fr33k at techie dot com
Looks identical to me?

# dpkg -l libc6
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Installed/Config-files/Unpacked/Failed-config/Half-installed
|/ Err?=(none)/Hold/Reinst-required/X=both-problems (Status,Err: uppercase=bad)
||/ Name                      Version                   Description
+++-=========================-=========================-==================================================================
ii  libc6                     2.3.2.ds1-12              GNU C Library: Shared libraries and Timezone data
 [2004-06-03 08:32 UTC] derick@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php4-STABLE-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php4-win32-STABLE-latest.zip

Hmm, can you try the latest snapshot please?
 [2004-06-03 20:48 UTC] fr33k at techie dot com
Unfortunately I cannot try the newer version as it is happening on a production server so there's no way the sysadmin would allow that. Development server is running 4.3.4 on RedHat 7.1 and it does not exhibit the problem. I found out we are running a non-stable version of Debian (debain-testing) so maybe that has something to do with the issue?
 [2004-06-04 14:50 UTC] derick@php.net
I run Debian-unstable and that works fine. Can you tar up your /usr/share/zoneinfo directory and email that to me?

regards,
Derick
 [2004-06-12 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2004-06-12 12:13 UTC] derick@php.net
This should be assigned to me...
 [2004-07-18 18:19 UTC] tumpen at fez dot dk
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).
 [2004-08-06 09:24 UTC] derrickbtan at gmail dot com
Same as previous comment: PHP5.  +1 day or 24 hour only adds to the day and not the hours.

$record = time();
echo date( "d:M H:i", $record );
echo "<br>";
echo date( "d:M H:i", strtotime( "+1 day", $record ) );

The relative times are taken from 00:00

dtan
 [2004-11-15 17:31 UTC] derick@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2011-10-23 16:47 UTC] gregg dot somes at gmail dot com
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
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 08:01:29 2024 UTC