0
votes

I am doing one small project and my client need Wednesday to Wednesday daily report button..

example: Today Tuesday..So he needs button like these.. Last week wednesday(7-02-2018) Lastweek thursday(8-02-2018) lastwek friday(9-02-2018) Last week saturday(10-02-2018) last Sunday(11-02-2018) Yesterday(12-02-2018) Today(13-02-2018)

And I tried,but it shows only near days..Can any one help me to get these dates dynamicaly..

function closestDate($day){
    $day = ucfirst($day);
    if(date('l', time()) == $day)
        return date("Y-m-d", time());
    else if(abs(time()-strtotime('next '.$day)) < abs(time()-strtotime('last '.$day)))
        return date("Y-m-d", strtotime('next '.$day));
    else
        return date("Y-m-d", strtotime('last '.$day));
}
echo closestDate('saturday');
1

1 Answers

0
votes

You can create code like this

    date("Y-m-d", strtotime("+1 week"));