Recently, I used PHP to get the current week and last week's start date and end date because of the work. Search the Internet, there is no suitable, so I did a summary. The specific content and code are as follows.
<?php
header (' content-type:text/html; Charset=utf-8 ');
$date =date (' y-m-d '); The current date
$first =1;//$first =1 indicates that weekly Monday is the start date 0 for each Sunday as the start date
$w =date (' W ', Strtotime ($date)); Gets the day of the current week Sunday is 0 weeks one to Saturday is 1-6
$now _start=date (' y-m-d ', Strtotime ("$date-". $w? $w-$first: 6). ' Days '); Get the start date for this week, if $w is 0, Sunday, minus 6 days
$now _end=date (' y-m-d ', Strtotime ("$now _start +6")); This week's end date
$last _start=date (' y-m-d ', Strtotime ("$now _start-7 Days")); Last week's start date
$last _end=date (' y-m-d ', Strtotime ("$now _start-1 Days")); Last week's end date
Echo ' This week's start date: ', $now _start, ' <br/> ';
Echo ' This week's End date: ', $now _end, ' <br/> ';
Echo ' last week's start date: ', $last _start, ' <br/> ';
Echo ' Last week's End date: ', $last _end, ' <br/> ';
Note: Since the foreign week is from Sunday onwards, China's custom from Monday onwards, so the direct use of Strtotime ("last Monday") will have the wrong results.
Articles that you may be interested in
- How PHP Gets the start time stamp and end time stamp for today, yesterday, last week, month
- PHP gets the timestamp of the start and end times of the week that the specified date is in
- PHP gets a list of dates 30 days before the current date
- PHP calculates the function of how many years, how many months, how many days apart two dates
- PHP in front of quotes to add the reason for the backslash and PHP to remove the backslash, three ways to turn off the PHP magic quotes
- PHP extracts the birthday date in the ID number and the function to verify that it is a minor
- PHP detects whether the server SSL is turned on and how to turn on SSL
- PHP to determine the most secure upload file type, the most realistic solution