Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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
You can’t perform that action at this time.