Home

Find the beginning and ending times of the week in PHP


Something I keep needing every once-in-a-while and I keep forgetting:

$diffday = date("w"); $addday = 7 - date("w"); 
$start_time=mktime(0,0,0,$month, ($day-$diffday), $year); 
$end_time=mktime(0,0,0,$month, ($day+$addday), $year);

This goes from the first second on Sunday to the last second on the next Saturday (first second in the next sunday). (e.g. 12am on 1/18/2004 -> 12am on 12/25/2004)