note 36504 added to function.strtotime

From: Date: Sun, 12 Oct 2003 23:02:56 +0000
Subject: note 36504 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-58346@lists.php.net to get a copy of this message
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 ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+36504 Delete -- http://master.php.net/manage/user-notes.php?action=delete+36504&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+36504&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#58346) next »