The question with the βcorrectβ answer is, what if the delivered date is Sunday? Then it will give you the previous Sunday instead of the current Sunday. The same question is with Saturday.
$s = 'Monday, September 28, 2009'; $time = strtotime($s); if(date('D', $time) == "Sun"){ $start = strtotime(' 12pm', $time); } else { $start = strtotime('last sunday, 12pm', $time); } if(date('D', $time) == "Sat"){ $start = strtotime(' 12pm', $time); } else { $start = strtotime('next saturday, 12pm', $time); } $format = 'l, F j, Y g:i A'; $start_day = date($format, $start); $end_day = date($format, $end); header('Content-Type: text/plain'); echo "Input: $s\nOutput: $start_day - $end_day";
Warren landis
source share