Well, I thought a simple google search and I would find an example to show you. Unfortunately, I did not find one (maybe somebody else is a better searcher.) Anyhow, I got thinking, this is something I'd like to put into my own bag of tricks for future projects. Thus, I hacked together the following function.
<?php
/**
* Returns array of unix timestamps representing work week specified.
*
* @param integer $year
* @param integer $weekOfYear
* @param integer $daysToAdd
* @return array
*/
function getWorkWeek($year,$weekOfYear, $daysToAdd=5)
{
/*** Set number of seconds date constants ***/
define("ONE_DAY", 60*60*24);
define("ONE_WEEK", ONE_DAY * 7);
/*** Initialize first day of specified year ***/
$firstDayOfYear = mktime(0,0,0,1,1,$year);
/*** Add days to first day of year until we
* finally end up with the first monday. ***/
$firstMonday = $firstDayOfYear;
while (date("w",$firstMonday) != 1) {
$firstMonday+=ONE_DAY;
}
/*** Get integer value of week of year first
* monday falls in... ***/
$firstWeekMondayIn = intval(date("W", $firstMonday));
/*** Determine weeks to add ***/
$weeksToAdd = $weekOfYear - $firstWeekMondayIn;
/*** Add weeks to find first monday of week
* of the year specified. ***/
$startdate = $firstMonday + (ONE_WEEK * $weeksToAdd);
/*** Add specified days to get end date ***/
$enddate = $startdate + ($daysToAdd * ONE_DAY);
/*** Build array of days in workweek range ***/
$dates = array();
for ($date=$startdate; $date<$enddate; $date+=ONE_DAY) {
$dates[] = $date;
}
return $dates;
}
?>
Probably not tested thoroughly enough. Test it and let me know if it works for you.