PHP retrieves the first and last days of the week. // The first and last days of the week. $ date = new & nbsp; DateTime (); $ date-& gt; modify ('This & nbsp; week '); $ first_day_of_week = $ date-& gt; format ('Y-m-D'); $ date-& gt; modify PHP get the first day and last day of the week
// The first and last days of the week
$ Date = new DateTime ();
$ Date-> modify ('This Week ');
$ First_day_of_week = $ date-> format ('Y-m-D ');
$ Date-> modify ('this week + 6 days ');
$ End_day_of_week = $ date-> format ('Y-m-D ');
Using PHP to get the first day and last day of the week, there are many methods on the internet. it is too troublesome to use functions, and there are some bugs. since the official website has a DateTime class, why is it rare to see someone using it? This is the answer from a foreign website. is this method reliable?
------ Solution --------------------
Reliable, no problem
------ Solution --------------------
This week
echo date('Y-m-d w', strtotime('this week'));
2014-02-17 1
We are Chinese and do not know much about how westerners express dates (especially programmers)
Besides, this statement does not conform to the fact that the week begins with Sunday.
Calculated based on the default php date, similar to writing
echo date('Y-m-d w', strtotime('last day this week'));
2014-02-16 0
------ Solution --------------------
Reference:
This week
echo date('Y-m-d w', strtotime('this week'));
2014-02-17 1
We are Chinese and do not know much about how westerners express dates (especially programmers)
Besides, this statement does not conform to the fact that the week begins with Sunday.
Calculated based on the default php date, similar to writing
echo date('Y-m-d w', strtotime('last day this week'));
2014-02-16 0
Powerful moderator
------ Solution --------------------
With a starting point, you are not afraid of having no ending point.
echo date('Y-m-d w', strtotime('last day this week +6 day'));
2014-02-22 6
------ Solution --------------------
Echo date ('Y-m-D', mktime (0, 0, 0, date ('M'), date ('D')-date ('w '), date ('Y'); // The first day
Echo date ('Y-m-D', mktime (0, 0, 0, date ('M'), date ('D ') + (6-date ('w'), date ('Y'); // The Last Day