5

Running

var_dump(new \DateTime('first day of this week'));

Returns the 1st of September

https://3v4l.org/GIPKR

Is this a bug, and is there any workaround?

enter image description here

Petah
  • 45,477
  • 28
  • 157
  • 213
  • Interesting. It has been discussed [here](http://stackoverflow.com/questions/1897727/get-first-day-of-week-in-php) – Raptor Oct 06 '16 at 02:23
  • Some of the PHP date functions do not seem to work as expected. jddayofweek is another one that did not work for me. – sdexp Oct 06 '16 at 02:27
  • I tried `last day of this week` as well. And it returned the last day of this month, which is Oct. 31. Weird. – Rax Weber Oct 06 '16 at 02:37
  • It is perfectly normal : the doc indicate that 'first day of' return the first day of a month : http://php.net/manual/en/datetime.formats.relative.php – Julien Bourdic Oct 07 '16 at 12:25
  • FWIW, I would never rely on the automagic of parsing human sentences, unless I completely understood how this parsing works and how my input will be interpreted. This isn't too hard to do "manually". – deceze Oct 07 '16 at 12:30

2 Answers2

1

Please try below code :

var_dump(new \DateTime('monday this week'));
Patrick R
  • 6,621
  • 1
  • 24
  • 27
-1

Refer to this - Finding First day of week via php Also try this -

        <?php 
            // var_dump(new \DateTime('first day of this week'));


            echo date("Y-m-d", strtotime('monday this week')), "<br/>\n";   

            echo date("Y-m-d", strtotime('sunday last week')), "<br/>\n";

        ?>
Community
  • 1
  • 1
T.Shah
  • 2,768
  • 1
  • 14
  • 13