A very small problem has been dealt with today.
The requirement is that, from Monday to Sunday, you can only see data from Monday to Sunday.
Here, you can query the range directly from the database based on the Date field.
But you need PHP to generate a start date and an end date.
In the beginning, I dealt with it directly.
Copy the Code code 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 2011-07-19, $start _date= 2011-07-11 to deal with it without problems.
If the date is 2011-07-18, the $start _date will be equal to 2011-07-04, still live in the last week.
So I changed the way.
Copy the Code code 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 2011-07-19, $start _date= 2011-07-11 This treatment is no problem, as we expected.
If the date is 2011-07-24, we expect the $start _date is 2011-07-11, but the actual return is 2011-07-18.
I have to change the method below.
Copy the Code code 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 will be OK.
The above describes the filial piety there are three no longer what is the meaning of an interesting date in PHP logic processing, including the filial piety has three no what the meaning of the content, I hope that the PHP tutorial interested friends have helped.