Bug #68973 [Com]: DateTime('first day of last week') not working

From: Date: Wed, 04 Feb 2015 04:21:44 +0000
Subject: Bug #68973 [Com]: DateTime('first day of last week') not working
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-190457@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=68973&edit=1 ID: 68973 Comment by: a at b dot c dot de Reported by: t dot baumgarden at web dot de Summary: DateTime('first day of last week') not working Status: Not a bug Type: Bug Package: Date/time related Operating System: centOS PHP Version: 5.5.21 Block user comment: N Private report: N New Comment: Assuming a culture that reckons weeks as running from Monday to Sunday and not, say, Sunday to Saturday. :) Previous Comments: ------------------------------------------------------------------------ [2015-02-03 07:38:11] aharvey@php.net What cmbecker69 said. :) ------------------------------------------------------------------------ [2015-02-02 21:41:43] cmbecker69 at gmx dot de According to the table "Day-based notations" on the manual page "Relative Formats"[1] "first day of" and "last day of" are always relative a *month*. What you're looking for is new DateTime('Monday of last week') resp. new DateTime('Sunday of last week') [1] <http://php.net/manual/en/datetime.formats.relative.php> ------------------------------------------------------------------------ [2015-02-02 16:42:06] t dot baumgarden at web dot de Description: ------------ Today is 2015-02-02 (02.February) I want first and last day ob last week: $date = new DateTime('first day of last week'); echo $date->format('Y-m-d'); // --- $date = new DateTime('last day of last week'); echo $date->format('Y-m-d'); result is (WRONG!): 2015-02-01 2015-02-28 MUST BE: 2015-01-26 2015-02-01 This working fine with "month" instead "week": DateTime('first day of last month'); DateTime('last day of last month'); result is: 2015-01-01 2015-01-31 Test script: --------------- $date = new DateTime('first day of last week'); echo $date->format('Y-m-d'); $date = new DateTime('last day of last week'); echo $date->format('Y-m-d'); Expected result: ---------------- 2015-01-26 2015-02-01 Actual result: -------------- 2015-02-01 2015-02-28 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=68973&edit=1

« previous php.bugs (#190457) next »