Today we have handled a very small problem.
This is the requirement. From Monday to Sunday, only data from last Monday to last Sunday can be seen.
Here we can query the range directly from the Database Based on the date field.
However, PHP needs to generate the start date and end date.
At the very beginning, I did this directly.Copy codeThe Code is as follows: $ start_date = date ('Y-m-d', strtotime ("-2 week Monday "));
$ End_date = date ('Y-m-d', strtotime ("$ start_date + 6 day "));
If the date is, $ start_date =, there is no problem.
If the date is, $ start_date is equivalent to and remains in the last week.
So I changed the method.Copy codeThe Code is as follows: $ getWeekDay = date ("w ");
$ StartDay = date ("Y-m-d", mktime (0, 0, 0, date ("m"), date ("d ") -$ getWeekDay + 1-7, date ("Y ")));
$ EndDay = date ("Y-m-d", strtotime ("+ 6 day $ startDay "));
If the date is, $ start_date =, there is no problem, as we expect.
If the date is, we expect $ start_date to be, but the actual return is 2011-07-18.
I have to change the method.Copy codeThe Code is as follows: $ getWeekDay = date ("N ");
$ StartDay = date ("Y-m-d", mktime (0, 0, 0, date ("m"), date ("d ") -$ getWeekDay + 1-7, date ("Y ")));
$ EndDay = date ("Y-m-d", strtotime ("+ 6 day $ startDay "));
This is OK.