PHP Gets the first day of the week and the last day

Source: Internet
Author: User
Tags echo date
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
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.