PHP gets the first and last day of the week
The first and last day 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 and last day of the week, there are many ways to use the function, the feeling is too troublesome, and some have bugs, since the official brought a DateTime class, why rarely see someone use? This is a foreign site to see the answer, this method is reliable?
------Solution--------------------
Reliable, no problem.
------Solution--------------------
This Week week
echo Date (' Y-m-d w ', Strtotime (' This week '));
2014-02-17 on 1
We are Chinese and don't know much about the way Westerners describe dates (especially programmers)
And this statement is not in line with the fact that Europe and the United States have been in the week since Sunday.
According to the default PHP date calculation, should write
echo Date (' Y-m-d w ', Strtotime (' Last day this Week '));
2014-02-16 on 0
------Solution--------------------
Citation:
this week this week
echo Date (' Y-m-d w ', Strtotime (' This week '));
2014-02-17 on 1
We are Chinese and don't know much about the way Westerners describe dates (especially programmers)
And this statement is not in line with the fact that Europe and the United States have been in the week since Sunday.
According to the default PHP date calculation, should write
echo Date (' Y-m-d w ', Strtotime (' Last day this Week '));
2014-02-16 0
Moderator powerful
------Solution--------------------
With a starting point, I'm afraid there's no end
echo Date (' Y-m-d w ', Strtotime (' Last day this week +6 Day '));
2014-02-22 on 6
------Solution--------------------
echo Date (' y-m-d ', Mktime (0,0,0,date (' m '), date (' d ')-date (' W '), date (' Y ')); First day
echo Date (' y-m-d ', Mktime (0,0,0,date (' m '), date (' d ') + (6-date (' W ')), date (' Y ')); Last day