Recently, due to work needs, php is used to obtain the start date and end date of the current week and last week. I found it online, but it was not suitable. So I made a summary myself. The specific content and Code are as follows.
<? Phpheader ('content-type: text/html; charset = UTF-8 '); $ date = date ('Y-m-d'); // current date $ first = 1; // $ first = 1 indicates that Monday is the start date 0, indicating that every Sunday is the start date $ w = date ('w', strtotime ($ date )); // obtain the day of the current week. The day from Sunday is 0 Monday to Saturday is 1-6 $ now_start = date ('Y-m-d', strtotime ("$ date -". ($ w? $ W-$ first: 6 ). 'Days '); // obtain the start date of the week. If $ w is 0, it indicates Sunday, minus 6 days $ now_end = date ('Y-m-d ', strtotime ("$ now_start + 6 days"); // end date of the week $ 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 end date echo 'start date of the week: ', $ now_start,' <br/> '; echo 'end date of the week: ', $ now_end,' <br/> '; echo 'start date of the last week:', $ last_start, '<br/> '; echo 'end Date of last week: ', $ last_end,' <br/> ';
Note: Since the weeks in foreign countries start from Sunday and China is used to start from Monday, an error occurs when strtotime ("last Monday") is used directly.
Articles you may be interested in
- Php obtains the start and end timestamps of today, yesterday, last week, and this month.
- Php obtains the start time and end time timestamp of the week of the specified date.
- PHP retrieves the date list for the first 30 days of the current date
- Php extracts the birthday date from the ID card number and verifies whether it is a minor.
- Reasons why PHP adds a backslash before the quotation mark and how PHP removes the backslash, there are three ways to disable the php magic quotation mark
- Php calculates the number of years, months, and days between two dates.
- Thinkphp automatic verification and automatic filling are invalid Solutions
- PHP obtains the week of the specified date, the first day of the month and the last day of the month.