php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #41873 strtotime produces incorrect output
Submitted: 2007-07-02 15:13 UTC Modified: 2008-01-31 20:30 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: kevin at creativeanvil dot com Assigned: derick (profile)
Status: Not a bug Package: Date/time related
PHP Version: 5.2.3 OS: RHEL 4
Private report: No CVE-ID: None
 [2007-07-02 15:13 UTC] kevin at creativeanvil dot com
Description:
------------
For the last friday of the month for several months it is incorrect.  Tends to happen when the last day of the month is on the date you're looking for.

Reproduce code:
---------------
$stamp = strtotime("last Friday", gmmktime(0,0,0,11,0,2007);
echo date("m/d/Y", $stamp)."<br>;

$stamp = strtotime("last Friday", gmmktime(0,0,0,8,0,2007);
echo date("m/d/Y", $stamp);



Expected result:
----------------
11/30/2007
8/31/2007

Actual result:
--------------
11/23/2007
8/24/2007

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-07-03 06:44 UTC] tony2001@php.net
Works perfectly fine here:
10/26/2007
07/27/2007
 [2007-07-03 19:30 UTC] kevin at creativeanvil dot com
Yes, most of the time it is correct, but I've found if the day wanted is the last day of the month, it may not work correctly.  Friday was an example, it probably has nothing to do with Friday specifically, that's just what I tested and found the problem.
 [2007-07-04 11:23 UTC] tony2001@php.net
So how to reproduce it?
 [2007-09-04 14:01 UTC] kevin at creativeanvil dot com
Doing this:

<?php
$stamp = strtotime("last Friday", gmmktime(0,0,0,11+1,0,2007));
echo date("m/d/Y", $stamp)."<br>";

$stamp = strtotime("last Friday", gmmktime(0,0,0,8+1,0,2007));
echo date("m/d/Y", $stamp);
?>

Expected Value:
11/30/2007
08/31/2007

Actual Value
11/23/2007
08/24/2007

That should make more sense.

Again this seems to happen when the last day of the month is the last Friday that we're looking for, then it returns the previous Friday.
 [2007-09-04 22:41 UTC] jani@php.net
Assigned to the ext/date maintainer.
 [2008-01-31 20:30 UTC] derick@php.net
There is no bug here.

If you use "2007-11-30 last friday" you get of course the previous friday, which is 2007-11-23.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 03 14:01:30 2024 UTC