php.net |  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
Votes:6
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
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: jorge at newsengin dot com
New email:
PHP Version: OS:

 

 [2004-09-09 21:24 UTC] jorge at newsengin dot com
Description:
------------
This seems related to the open bug involving "now" 
resetting to midnight of the current day, but it's not 
identical.

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.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-09-10 09:16 UTC] derick@php.net
I think it's the same bug after all, will add it to my list.
 [2004-11-15 17:35 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.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 13:01:29 2024 UTC