Created
January 18, 2011 01:58
-
-
Save sp3c73r2038/783872 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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