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, we also need to determine the events occurred in all days of the current month, and use the specified date to determine the day of the week... syntaxHighlighter. all ();
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, 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