|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30042 strtotime does not use second param
Submitted: 2004-09-09 21:24 UTC Modified: 2004-11-15 17:35 UTC
Avg. Score:5.0 ± 0.0
Reproduced:6 of 6 (100.0%)
Same Version:1 (16.7%)
Same OS:0 (0.0%)
From: jorge at newsengin dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.0.1 OS: OS X Panther
Private report: No CVE-ID: None
 [2004-09-09 21:24 UTC] jorge at newsengin dot com
This seems related to the open bug involving "now" 
resetting to midnight of the current day, but it's not 

If you try to adjust a time by passing strtotime() an 
offset like "+2 hours", you get that offset relative to 
midnight.  In other words, strtotime("+2 hours", 
$unixtimestamp) returns a timestamp for 2 a.m, of the 
day referenced by $unixtimestamp, or of the current day 
if the second argument is omitted.

Reproduce code:
// in PHP 4, this correctly returns 3:30 p.m. on Jan 1, 2005 but in PHP 5.0.1 returns 2:00 a.m. on Jan 1, 2005:

$timeStamp = strtotime("+2 hours", strtotime("1/1/2005 1:30pm"));
echo date("r", $timeStamp);

// in PHP 4, this correctly returns a date/time for two hours from now, but in PHP 5.0.1 it returns 2 a.m. on the current day:
$timeStamp = strtotime("+2 hours");
echo date("r", $timeStamp);

Expected result:
two hours from given date and time or from now, 
depending on whether a second timestamp argument was 
provided to strtotime();

Actual result:
2 a.m. on relevant date.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-10 09:16 UTC]
I think it's the same bug after all, will add it to my list.
 [2004-11-15 17:35 UTC]
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
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Mar 04 21:01:31 2024 UTC