Edit report at https://bugs.php.net/bug.php?id=63740&edit=1
ID: 63740
Comment by: mateusz dot m dot nowaczyk at gmail dot com
Reported by: salmanarshad2000 at yahoo dot com
Summary: strtotime seems to use both sunday and monday as
start of week
Status: Open
Type: Bug
Package: Date/time related
PHP Version: 5.4.9
Block user comment: N
Private report: N
New Comment:
I spent hours of scratching my head and analyzing SQL queries because of this bug - some financial
reports were incorrectly calculated due to this behavior. I eventually implemented some ugly
workaround. Why isn't this fixed, after three years?
Previous Comments:
------------------------------------------------------------------------
[2016-02-03 10:30:09] szeli dot zsolt at hotmail dot com
similar problem ... when get actual week first and last day.
first day is: strtotime('this week last monday')
last day is: strtotime('this week next sunday') is coming back to the next week on sunday,
so have to strtotime('this week last monday + 6 days')
------------------------------------------------------------------------
[2015-07-13 09:51:53] mrtreinis at gmail dot com
This is a rather horrible bug, bumping for pressure.
Another test sample:
(date)->modify('Monday this week')
2015-07-06: 2015-07-06 // Mo - Mo
2015-07-07: 2015-07-06 // Tu - Mo
2015-07-08: 2015-07-06 // We - Mo
2015-07-09: 2015-07-06 // Th - Mo
2015-07-10: 2015-07-06 // Fr - Mo
2015-07-11: 2015-07-06 // Sa - Mo
2015-07-12: 2015-07-13 // Su - Mo next week???!!!
------------------------------------------------------------------------
[2014-10-27 09:14:10] ca at noyo dot dk
I agree with salmanarshad2000, something's wrong here.
googleguy@php.net explains how "this week" is normalized:
"Sat 2012-12-08" is normalized to "Mon 2012-12-03"
"Sun 2012-12-09" is normalized to "Mon 2012-12-10".
This seems wrong, the two days are in the same week. They should both normalize to "Mon
2012-12-03".
------------------------------------------------------------------------
[2013-02-11 17:34:54] timakeeling at gmail dot com
Related To: Bug #64181
------------------------------------------------------------------------
[2013-01-24 08:31:06] salmanarshad2000 at yahoo dot com
The latter part which explains that "Sunday this week" is evaluated as (i) this week (ii)
very next sunday is well explained and understandable.
The former part which mentions that "time argument of strtotime() such as this week [is
interpreted as] a week period of Monday through Sunday" is still
confusing. It does return a Monday but does it return the correct Monday?
/* when today is */ /* this
week is */
/* Mon 2012-12-03 */ echo date("D Y-m-d", strtotime("this week",
strtotime("2012-12-03"))); /* Mon 2012-12-03 */
/* Tue 2012-12-04 */ echo date("D Y-m-d", strtotime("this week",
strtotime("2012-12-04"))); /* Mon 2012-12-03 */
/* Wed 2012-12-05 */ echo date("D Y-m-d", strtotime("this week",
strtotime("2012-12-05"))); /* Mon 2012-12-03 */
/* Thu 2012-12-06 */ echo date("D Y-m-d", strtotime("this week",
strtotime("2012-12-06"))); /* Mon 2012-12-03 */
/* Fri 2012-12-07 */ echo date("D Y-m-d", strtotime("this week",
strtotime("2012-12-07"))); /* Mon 2012-12-03 */
/* Sat 2012-12-08 */ echo date("D Y-m-d", strtotime("this week",
strtotime("2012-12-08"))); /* Mon 2012-12-03 */
/* Sun 2012-12-09 */ echo date("D Y-m-d", strtotime("this week",
strtotime("2012-12-09"))); /* Mon 2012-12-10 */
/* Mon 2012-12-10 */ echo date("D Y-m-d", strtotime("this week",
strtotime("2012-12-10"))); /* Mon 2012-12-10 */
/* Tue 2012-12-11 */ echo date("D Y-m-d", strtotime("this week",
strtotime("2012-12-11"))); /* Mon 2012-12-10 */
/* Wed 2012-12-12 */ echo date("D Y-m-d", strtotime("this week",
strtotime("2012-12-12"))); /* Mon 2012-12-10 */
/* Thu 2012-12-13 */ echo date("D Y-m-d", strtotime("this week",
strtotime("2012-12-13"))); /* Mon 2012-12-10 */
/* Fri 2012-12-14 */ echo date("D Y-m-d", strtotime("this week",
strtotime("2012-12-14"))); /* Mon 2012-12-10 */
/* Sat 2012-12-15 */ echo date("D Y-m-d", strtotime("this week",
strtotime("2012-12-15"))); /* Mon 2012-12-10 */
/* Sun 2012-12-16 */ echo date("D Y-m-d", strtotime("this week",
strtotime("2012-12-16"))); /* Mon 2012-12-17 */
You can see that the output changes on Sundays, not Mondays. Expected:
"this week" on Sun 2012-12-09 should return the week starting Mon 2012-12-03 (ending on
Sun 2012-12-09 inclusive)
"this week" on Sun 2012-12-16 should return the week starting Mon 2012-12-10 (ending on
Sun 2012-12-16 inclusive)
Actual:
this week on Sun 2012-12-09 returns the week starting _coming_ Mon 2012-12-10
this week on Sun 2012-12-16 returns the week starting _coming_ Mon 2012-12-17
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=63740
--
Edit this bug report at https://bugs.php.net/bug.php?id=63740&edit=1