I'm trying to write a script that will set the dat to the previous monday from today's date. the script that I have come up with (I'm new to this) is
$today=getdate();
$day=$today[wday];
if($day == 1) $beg_date = date('Y-m-d');
else if($day == 2) $beg_date = date('Y-m-d', mktime(0,0,0,date('m'),date('d')-1,date('Y')));
else if($day == 3) $beg_date = date('Y-m-d', mktime(0,0,0,date('m'),date('d')-2,date('Y')));
else if($day == 4) $beg_date = date('Y-m-d', mktime(0,0,0,date('m'),date('d')-3,date('Y')));
else if($day == 5) $beg_date = date('Y-m-d', mktime(0,0,0,date('m'),date('d')-4,date('Y')));
else if($day == 6) $beg_date = date('Y-m-d', mktime(0,0,0,date('m'),date('d')-5,date('Y')));
else if($day == 0) $beg_date = date('Y-m-d', mktime(0,0,0,date('m'),date('d')-6,date('Y')));
This seems to work except for when the previous monday was part of the previous month, then it seems like one of the negative calculations is used to jump to the previous month and therefore I get he previous tuesday instead of monday. Any suggestions for how to improve this script?