Created
November 23, 2012 10:44
-
-
Save fetus-hina/4135068 to your computer and use it in GitHub Desktop.
Calculate date by ISO-Week-Number (and wday)
This file contains 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 | |
function weekNumberToDate($year, $week, $wday = 1) { | |
// http://en.wikipedia.org/wiki/ISO_week_date#Calculating_a_date_given_the_year.2C_week_number_and_weekday | |
$correction = (int)gmdate('w', gmmktime(0, 0, 0, 1, 4, (int)$year)) + 3; | |
$yday = (int)$week * 7 + (int)$wday - $correction; | |
$time = gmmktime(0, 0, 0, 1, $yday, (int)$year); | |
return array((int)gmdate('Y', $time), (int)gmdate('n', $time), (int)gmdate('j', $time)); | |
} | |
var_dump(weekNumberToDate(2008, 39, 6)); |
ROBERT-MCDOWELL
commented
Apr 28, 2017
•
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment