Hey. This is a function I put together to return timestamps for the first and last day of the week given to it. It seems to work correctly, so if anyone feels like playing with it, suggestions and/or improvements are very welcome.
/*
* get_week_range accepts numeric $month, $day, and $year values.
* It will find the first sunday and the last saturday of the week for the
* given day, and return them as YYYY-MM-DD HH:MM:SS timestamps
*
* @param month: numeric value of the month (01 - 12)
* @param day : numeric value of the day (01 - 31)
* @param year : four-digit value of the year (2008)
* @return : array('first' => sunday of week, 'last' => saturday of week);
*/
function get_week_range($day='', $month='', $year='') {
// default empties to current values
if (empty($day)) $day = date('d');
if (empty($month)) $month = date('m');
if (empty($year)) $year = date('Y');
// do some figurin'
$weekday = date('w', mktime(0,0,0,$month, $day, $year));
$sunday = $day - $weekday;
$start_week = date('Y-m-d H:i:00', mktime(0,0,0,$month, $sunday, $year));
$end_week = date('Y-m-d H:i:00', mktime(0,0,0,$month, $sunday+6, $year));
if (!empty($start_week) && !empty($end_week)) {
return array('first'=>$start_week, 'last'=>$end_week);
}
// otherwise there was an error :'(
return false;
}