php first monday after certain date as string

后端 未结 2 430
执念已碎
执念已碎 2020-12-20 18:33

I have a date given as a string. And I would like to get the first monday after this given date, again as a string.

$myDate = \"2014-08-24\"; // date given i         


        
相关标签:
2条回答
  • 2020-12-20 19:01

    you can use this

    <?php
    $myDate = "2014-08-27";
    $next_monday = date('Y-m-d', strtotime("next monday", strtotime($myDate)));
    echo $next_monday;
    ?>
    

    OUTPUT :

    2014-09-01
    

    Demo

    0 讨论(0)
  • 2020-12-20 19:06

    You can do it using the DateTime and DateTime::modify

    $date = new DateTime('2014-08-24');
    $date->modify('next monday');
    echo $date->format('Y-m-d') . "\n";
    
    0 讨论(0)
提交回复
热议问题