Dealt with a very small issue 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 like this directly.
Copy the 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"));
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"));
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" ));
The above has introduced an interesting date logic processing in PHP, including the content of what it means to be unfilial and unfilial, and I hope it will be helpful to friends who are interested in PHP tutorials.