php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54409 strtotime(): "this week" gives incorrect result for Sunday dates
Submitted: 2011-03-28 17:20 UTC Modified: 2016-08-07 09:27 UTC
Votes:8
Avg. Score:3.9 ± 0.9
Reproduced:8 of 8 (100.0%)
Same Version:2 (25.0%)
Same OS:2 (25.0%)
From: 1234 dot ia at gmail dot com Assigned: derick (profile)
Status: Duplicate Package: Date/time related
PHP Version: 5.3.6 OS: Linux 2.6.36-hardened
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: 1234 dot ia at gmail dot com
New email:
PHP Version: OS:

 

 [2011-03-28 17:20 UTC] 1234 dot ia at gmail dot com
Description:
------------
When trying to get relative dates, strtotime() gives incorrect result for relative format "{weekday} this week" when the base date is Sunday. It should return the same day, as it does with other weekdays, but it returns next week's day.

Test script:
---------------
<?php

error_reporting( -1 );
date_default_timezone_set( "Europe/Bratislava" );

for ( $i = 0; $i < 7; $i++ )
{

	$base = strtotime( "2011/01/17 +$i days 12:00:00" );
	$weekday = date( "l", $base );
	$relative = strtotime( "$weekday this week 12:00:00", $base );
	
	echo date( "l Y/m/d", $base ), "\n", date( "l Y/m/d", $relative ), "\n\n";
}

?>

Expected result:
----------------
Monday 2011/01/17
Monday 2011/01/17

Tuesday 2011/01/18
Tuesday 2011/01/18

Wednesday 2011/01/19
Wednesday 2011/01/19

Thursday 2011/01/20
Thursday 2011/01/20

Friday 2011/01/21
Friday 2011/01/21

Saturday 2011/01/22
Saturday 2011/01/22

Sunday 2011/01/23
Sunday 2011/01/23

Actual result:
--------------
Monday 2011/01/17
Monday 2011/01/17

Tuesday 2011/01/18
Tuesday 2011/01/18

Wednesday 2011/01/19
Wednesday 2011/01/19

Thursday 2011/01/20
Thursday 2011/01/20

Friday 2011/01/21
Friday 2011/01/21

Saturday 2011/01/22
Saturday 2011/01/22

Sunday 2011/01/23
Sunday 2011/01/30

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-03-28 21:06 UTC] derick@php.net
-Status: Open +Status: Assigned -Assigned To: +Assigned To: derick
 [2012-03-31 09:54 UTC] milan dot matejcek at gmail dot com
Bug persists (php 5.3.10), in our country (Czech) week start on Monday. 
If you set Saturday for example (31-03-2012) on your machine 
var_dump(new DateTime('monday this week'));//26-03-2012

Now let's set Sunday (01-04-2012) on your machine
var_dump(new DateTime('monday this week'));//actual 02-04-2012, expected 26-03-
2012

help is variable set first day of week.
 [2014-11-02 21:42 UTC] karl at ivide dot com
A variation on this is that the following code run on a saturday or sunday yields monday's date, not the same date as one would expect. Tried on PHP 5.6 on Windows.

echo date('Y-m-d', strtotime("+0 weekdays"));

However,

echo date('Y-m-d', strtotime("+0 days"));

Works as expected.
 [2016-08-07 09:27 UTC] cmb@php.net
-Status: Assigned +Status: Duplicate
 [2016-08-07 09:27 UTC] cmb@php.net
This is a duplicate of bug #63740, which has been fixed as of PHP
5.6.23 and 7.0.8, respectively (see <https://3v4l.org/qelbK>).
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jan 02 12:01:29 2025 UTC