php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41944 strtotime() not recognizing times before day
Submitted: 2007-07-09 21:00 UTC Modified: 2007-07-11 21:41 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: bealdrid at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2.3 OS: Fedora 7
Private report: No CVE-ID: None
 [2007-07-09 21:00 UTC] bealdrid at gmail dot com
Description:
------------
when calling the strtotime() function and when passing a time before the day such as "1pm yesterday" the wrong timestamp is returned, often midnite of that particular day.  


Reproduce code:
---------------
echo date('Y-m-d H:i:s',strtotime('1pm yesterday'));



Expected result:
----------------
The expected result would be 

2007-07-08 13:00:00 and this works in php 4.3.9

If I put the time after the day, such as "yesterday 1pm", it behaves as expected.  



Actual result:
--------------
2007-07-08 00:00:00

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-11 21:04 UTC] derick@php.net
This is not a bug, but a design choice. The new parser "Executes" the different parts of the string in order. So first "yesterday" and then "1am" moves to yesterday midnight first, and then to 1am. The opposite way first moves it to "1am" of the current day, and then back to yesterday midnight.
 [2007-07-11 21:38 UTC] bealdrid at gmail dot com
Thanks for the insight; the process that the string is "executed" makes sense.  But why the change?  We have code written and tested with PHP 4.3.9, which is now partially broken due to the change in design choice you reference.  What might you suggest would be a work around to get the desired result, as I used to get in 4.3.9?
 [2007-07-11 21:41 UTC] derick@php.net
It was changed not deliberately, but the old parser had no design and was impossible to maintain. As for a workaround, switch around "yesterday" and "1am" ?
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 19 22:00:03 2025 UTC