Get date for monday and friday for the current week (PHP)

后端 未结 8 1404
情话喂你
情话喂你 2020-12-01 03:46

How can I get the date for monday and friday for the current week?

I have the following code, but it fails if current day is sunday or saturday.

$cu         


        
8条回答
  •  渐次进展
    2020-12-01 04:21

    As the top answer suggests, using PHP's strtotime() function is the easiest way.

    However, instead of using if statements as he suggests, you could simply reset back to the previous Sunday and grab the dates you require from there.

    $monday = strtotime('next monday', strtotime('previous sunday'));
    $friday = strtotime('next friday', strtotime('previous sunday'));
    

提交回复
热议问题