Dealt with a very small problem today.
The demand is such that from Monday to Sunday you can only see the data from last Monday to last Sunday.
Here you can query the range directly from the database based on the date field.
But PHP is required to generate the start date and end date.
At first, I handled it this way.
Copy code The 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 2011-07-19, $start_date= 2011-07 -11 There is no problem with this.
If the date is 2011-07-18, $start_date will be equal to 2011-07-04, which is still alive in the last week.
So I changed the method
Copy the code The 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 2011-07-19, $start_date= 2011- 07-11 There is no problem with this processing, just as we expected.
If the date is 2011-07-24, we expect $start_date to be 2011-07-11, but what is actually returned is 2011-07-18.
As a last resort, I changed the method
Copy the code The 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.
http://www.bkjia.com/PHPjc/325208.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325208.htmlTechArticleA small problem was solved today. The demand is such that from Monday to Sunday only the data from last Monday to last Sunday can be seen. Here, query the range directly from the database based on the date field...