Skip to content

Instantly share code, notes, and snippets.

@sp3c73r2038
Created January 18, 2011 01:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sp3c73r2038/783872 to your computer and use it in GitHub Desktop.
Save sp3c73r2038/783872 to your computer and use it in GitHub Desktop.
<?php
/* input the year and week you want, then get the date! */
function getFirstDayOfWeek($year, $weeknr, $date_format="Y-m-d"){
$offset = date('w', mktime(0,0,0,1,1,$year));
$offset = ($offset < 5) ? 1-$offset : 8-$offset;
$monday = mktime(0,0,0,1,1+$offset,$year);
$date = strtotime('+' . ($weeknr - 1) . ' weeks', $monday);
return date($date_format,$date);
}
/* test. check the calendar:) */
echo getFirstDayOfWeek(2010,11),"\n";
echo getFirstDayOfWeek(2010,45),"\n";
echo getFirstDayOfWeek(2011,1),"\n";
echo getFirstDayOfWeek(2011,6),"\n";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment