PHP gets the start date and end date for this week and last week

Source: Internet
Author: User
<?phpheader (' content-type:text/html; Charset=utf-8 '); $date =date (' y-m-d ');  Current date $first=1; $first =1 represents the start date of the week Monday for the beginning of 0 per Sunday for the start date $w=date (' W ', Strtotime ($date));  Get the day of the current week Sunday is 0 weeks a to Saturday is 1-6 $now _start=date (' y-m-d ', Strtotime ("$date-". $w? $w-$first: 6). ' Days '); Gets the start date of the week, if $w is 0, then represents Sunday, minus 6 $now_end=date (' y-m-d ', Strtotime ("$now _start +6 Days");  This week's End date $last_start=date (' y-m-d ', Strtotime ("$now _start-7 Days"));  Last week start date $last_end=date (' y-m-d ', Strtotime ("$now _start-1 Days"));  Last week End date echo ' This week start date: ', $now _start, ' <br/> '; Echo ' This week's End date: ', $now _end, ' <br/> '; Echo ' last week start date: ', $last _start, ' <br/> '; Echo ' last week's End date: ', $last _end, ' <br/> ';

Note: Since the foreign week begins in Sunday, the Chinese habit starts from Monday, so the direct use of Strtotime ("last Monday") will result in incorrect results.

PHP gets the start date and end date for this week and last week

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.