PHP Development notes-commonly used date acquisition methods in weekly/weekly operations-PHP Tutorial

Source: Internet
Author: User
Notes on PHP Development-commonly used date acquisition methods in weekly and weekly operations. This Monday echodate (Y-m-d, (time ()-(date (w) 0? 7: date (w)-1) * 24*3600); w is the number of the day of the week. Here 0 is the echodate (Y-m-d, (time () + (7-(date (w) 0? 7. Monday
Echo date ('Y-m-D', (time ()-(date ('w') = 0? 7: date ('w')-1) * 24*3600); // w indicates the number of weeks. 0 indicates Sunday.

This Sunday

Echo date ('Y-m-D', (time () + (7-(date ('w') = 0? 7: date ('w') * 24*3600); // w is also used, which is calculated based on the number of days Currently related to Sunday.

Last Monday

Echo date ('Y-m-D', strtotime ('-1 Monday', time (); // no matter the number of today, -1 Monday indicates the last valid week.

Last Sunday

Echo date ('Y-m-D', strtotime ('-1 Sunday', time (); // the last valid Sunday, also applies to other weeks

1st day of this month

Echo date ('Y-m-D', strtotime (date ('Y-M', time (). '-01 00:00:00'); // Generate strtotime directly

Last day of this month

Echo date ('Y-m-D', strtotime (date ('Y-M', time ()). '-'. date ('t', time ()). '00:00:00'); // t indicates the number of days in the current month, 28 to 31 days.

1st day of last month

Echo date ('Y-m-D', strtotime ('-1 month', strtotime (date ('Y-M', time ()). '-01 00:00:00'); // subtract one month from strtotime on January 1, 1st day of this month.

Last day of last month

Echo date ('Y-m-D', strtotime (date ('Y-M', time ()). '-01 00:00:00')-86400); // minus one day on January 1, 1st day of this month is the last day of the previous month.

Reprinted from http://hi.baidu.com/panez/item/bc88803f487955f2a884289d

Explain echo date ('Y-m-D', (time ()-(date ('w') = 0? 7: date ('w')-1) * 24*3600); // w is a number of the day of the week, here 0 is Sunday echo date ('Y-m-D', (time () + (7-(date ('w') = 0? 7...

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.