php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #49981 strtotime work on sunday as a first day of week
Submitted: 2009-10-24 00:20 UTC Modified: 2009-10-30 01:37 UTC
From: shokarta at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.2SVN-2009-10-24 (snap) OS: WinXP SP2/AppServ2.5.9
Private report: No CVE-ID: None
 [2009-10-24 00:20 UTC] shokarta at gmail dot com
Description:
------------
Got a timestamp for sunday 1319281200 (its Sunday 23.10.2011), date("W") 
says its 42nd week of the year.

if i do strtotime("this monday",1319281200) then it will return: 
1319367600 which is monday 24.10.2011 and date("W") says its 43rd week 
on that year..

so simply strtotime works that sunday is a first day in a week instead 
of date which makes monday as a first day...

can i configure strtotime to work on monday as a first day as well?

Reproduce code:
---------------
strtotime("this monday",1319281200);

Expected result:
----------------
1318762800 (week 42, monday, 17/10/2011)

Actual result:
--------------
1319367600 (week 43, sunday, 24/10/2011)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-10-24 00:40 UTC] shokarta at gmail dot com
can make it works like this:
$actual_week = date("Y\WW",1319281200);
$real_result = strtotime("this monday",strtotime($actual_week));
but its only for this specific error
 [2009-10-24 21:03 UTC] sniper@php.net
Check your timezone. Always use gmdate() to not get such surprises.
There is no bug here.
 [2009-10-30 01:37 UTC] shokarta at gmail dot com
for example try this:
use date 1st of April 2009 (its wednesday).

echo date("j.m.Y",strtotime("last Monday",strtotime("04/01/2009"))); 
// RESULT is 30.03.2009 (should be 23.03.2009)
echo date("j.m.Y",strtotime("this Monday",strtotime("04/01/2009"))); 
// RESULT is 06.04.2009 (should be 30.04.2009)
echo date("j.m.Y",strtotime("next Monday",strtotime("04/01/2009"))); 
// RESULT is 06.04.2009 (should be 06.04.2009) - CORRECT

just found out that "this" doesnt work or works only as itself wants.

if i accidently jump on timestamp which stands for any Monday, then 
"last Monday" should show 1 week ago, "this monday" should show this 
day, "next monday" should show 1 week later!

but it wont show like this!

another example:

$month_min = strtotime("2009-01-01");
  for($i=0; $i<12; $i++)
   {
    $month = strtotime("+$i months",$month_min);
    $month = strtotime("last Monday",$month); }
    echo date("d.m.Y",$month)."<br>";
   }
  unset($i);

once u load the page then change code from "last Monday" to "this 
Monday" and once you reload only some of them will change! (and 
sometimes when you cange it back to "last Monday" and reload again 
then some of the others will change even when they didnt change 
before!

still not a bug?
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun May 05 13:01:30 2024 UTC