Obtain the day of the week _ PHP Tutorial

Source: Internet
Author: User
Returns the day of a week. In the previous project development process, a calendar month and a calendar week were required. because there was too little project experience at that time, the formatted time was saved to the database during the storage time, in addition, during the project development process, you need to write a calendar month and a calendar week. because there was too little project experience at that time, the formatted time was saved to the database during the storage time, it also determines the events that occur in all days of the current month, and uses the function of giving a specified date to determine the day of the week. Therefore, it creates unnecessary trouble for later processing.

Later, I checked some related information on the Internet and compiled a simple function based on my learning knowledge. now I post the code for your reference only. if you have any shortcomings, I forget to criticize it.

1 ./*

2. * function: obtain the number of days in a specified year, month, or week.

3. * parameter passing: string in the format of year, month, and day: 2010-01-01

4. * return value: calculated weekly value

5. * creator: FrancisRan

6. * creation Time: 2010-07-13

7. * last Modification time: 2010-07-13

8. * copyright (c) 2010 ranfanwei1988@126.com

9 .*/

10. function transition ($ date ){

11. $ datearr = explode ("-", $ date); // use "-" to split the sent time into an array.

12. $ year = $ datearr [0]; // Obtain the year

13. $ month = sprintf ('% 02d', $ datearr [1]); // Obtain the month

14. $ day = sprintf ('% 02d', $ datearr [2]); // get the date

15. $ hour = $ minute = $ second = 0; // the default time, minute, and second values are 0.

16. $ dayofweek = mktime ($ hour, $ minute, $ second, $ month, $ day, $ year); // Convert the time to a timestamp

17. return date ("w", $ dayofweek); // Obtain the week value

18 .}

This article is from the "FrancisRan" blog

...

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.