note 47435 deleted from function.date by tularis

From: Date: Sun, 30 Jan 2005 14:41:33 +0000
Subject: note 47435 deleted from function.date by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-84238@lists.php.net to get a copy of this message
Note Submitter: burkard dot schemmel at gmx dot de ---- Ever had trouble about german calculation of number of weeks in a certain year? Of course, there's date("W"), which wil be correct according to ISO standard. But what to do if you want to have a list of weeks in a certain year? If you use date("W"), your last week of a year may be 1. Thats correct. But you also have to change the year then - e.g. December 31th 2002 is in week 1 of the year 2003! This little script will help you out: function getWeeksOfYear($aYear) { $arrWeek = array(); $ts = mktime(0,0,0,12,31,$aYear); $ts2 = mktime(0,0,0,12,24,$aYear); $lastkw = date ("W", $ts); $lastyear = date ("Y", $ts); $lastkw2 = date ("W", $ts2); $lastyear2 = date ("Y", $ts2); if ($lastkw == "1") $lastyear = $lastyear+1; for($i=1;$i<=$lastkw2;$i++) { $arrWeek[$i-1]['kw'] = $i; $arrWeek[$i-1]['year'] = $lastyear2; } $arrWeek[$i]['kw'] = $lastkw; $arrWeek[$i]['year'] = $lastyear; return $arrWeek; } More information available here: http://www.salesianer.de/util/kalfaq.html#B3

« previous php.notes (#84238) next »