简体   繁体   中英

How to get wednesday to wednesday dates in php

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');

您可以创建这样的代码

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM