STRTOTIME to find current week, date for Monday and Saturday, PHP
date, php, strtotime
Solution
why don't you try like this
//check the current day
if(date('D')!='Mon')
{
//take the last monday
$staticstart = date('Y-m-d',strtotime('last Monday'));
}else{
$staticstart = date('Y-m-d');
}
//always next saturday
if(date('D')!='Sat')
{
$staticfinish = date('Y-m-d',strtotime('next Saturday'));
}else{
$staticfinish = date('Y-m-d');
}
Problem
I have these lines: ``` $staticstart = date('Y-m-d',strtotime('last Monday')); $staticfinish = date('Y-m-d',strtotime('next Saturday')); ``` And I am using them to select the monday and saturday of the current week, But when it is actually Monday, it choses the monday of the previous week, thus showing 2 weeks of data.... I have tried this and it produces no result: ``` $staticstart = date('Y-m-d',strtotime('this Monday')); ``` What have I missed? Is there a better way to find the monday and Saturday (dates) of the current week?