Get first/last day of week in php?

前端 未结 4 1289
说谎
说谎 2021-01-23 22:49

With get the date of the first day of the week and last day of the week in php, first day Monday and the last day Friday, for example I have the date 2017-05-23 and I want to kn

4条回答
  •  爱一瞬间的悲伤
    2021-01-23 23:30

    My solve,

    $datenow = date('Y-m-d');// date now
    $mon = new DateTime($datenow);
    $fri = new DateTime($datenow);
    $mon->modify('Last Monday');
    $fri->modify('Next Friday');
    

    using echo

    echo 'Monday: '.$mon->format('Y-m-d').'
    '; echo 'Friday: '.$fri->format('Y-m-d').'
    ';

    using var_dump()

    var_dump($mon);
    var_dump($fri);
    

提交回复
热议问题