php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #35983 strtotime(string, now) behavior has changed
Submitted: 2006-01-12 19:51 UTC Modified: 2006-01-13 15:14 UTC
From: tim at komta dot com Assigned: derick (profile)
Status: Not a bug Package: Date/time related
PHP Version: 5.1.2 OS: Windows XP Pro, Server 2003
Private report: No CVE-ID: None
 [2006-01-12 19:51 UTC] tim at komta dot com
Description:
------------
Prior to PHP 5.1.2 (potentially earlier, just only noticed it) strtotime(), when used with the optional 'now' argument, would return the time using the full 'now'.  Now it returns 00:00 on the date of the 'now', ignoring hours, minutes, and seconds.

Reproduce code:
---------------
$this_morning 	= strtotime('today 00:00:00');
$tonight		= strtotime('today 23:59:59');

echo date('m/d Hi', strtotime('yesterday', $this_morning)).'<br/>';
echo date('m/d Hi', strtotime('yesterday', $tonight)).'<br/>';

Expected result:
----------------
(as of 2005-01-12):

01/11 0000
01/11 2359

Actual result:
--------------
(as of 2005-01-12):

01/11 0000
01/11 0000

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-01-13 09:15 UTC] sniper@php.net
Assigned to the date man.
 [2006-01-13 12:01 UTC] derick@php.net
This is proper behavior. In the past PHP has been inconsistent regarding different terms like this. With the new code in PHP 5.1 this all works the same. What you want to do is by using:

"-1 day" or "1 day ago".
 [2006-01-13 15:14 UTC] tim at komta dot com
That's quite unfortunate that this is the newly intended behavior, both in the inadequate documentation and the actual breaking from prior behavior.  For such a major change, I really feel that the documentation of the function should have been updated to reflect this.

I rely (relied, I guess) on this to work for expanding to ranges...when my users search for "yesterday" they really meant "yesterday 00:00:00 through yesterday 23:59:59" which was easily handled by using different relative points in the day.  This new behavior completely breaks my search engine, and as of now, I don't see any way to fix this, short of having my users type in a more explicit date range they want.

I'm not sure that I see the inconsistancy.  "yesterday", relative to a timestamp, should return a timestamp that's 24 hours less than the timestamp given.  I see it as far more inconsistant that it could be anywhere from 24 hours less to 47:59:59 less.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 13:01:32 2024 UTC