note 36504 deleted from function.strtotime by sniper

From: Date: Tue, 21 Oct 2003 11:00:00 +0000
Subject: note 36504 deleted from function.strtotime by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-58988@lists.php.net to get a copy of this message
Note Submitter: pkr at teleca dot pl ---- I noticed that the posts regarding calculations of Monday out of given week and year (functions get_monday quoted somewhere above) are not quite correct -- they are not ISO compliant. They assume that week 1 is the week containing January, 1st. This is not correct. According to ISO standard, week 1 is the week which has majority of days belong to the new year. The crucial date is January, 4th. If it belongs to a given week - then it is the one and only, ISO compliant, Week One of the year. The corrected code could look as below: function get_monday($week, $year="") { $first_date = strtotime("4 january ".($year ? $year : date("Y"))); if(date("w", $first_date)==1) $monday = $first_date; else $monday = strtotime("last monday", $first_date); $plus_week = "+".($week-1)." week"; return strtotime($plus_week, $monday); } Cheers, Przemek

« previous php.notes (#58988) next »