note 38661 deleted from function.strftime by derick

From: Date: Sun, 14 Aug 2005 12:04:49 +0000
Subject: note 38661 deleted from function.strftime by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-93629@lists.php.net to get a copy of this message
Note Submitter: vesa dot kivisto at nepton dot fi ---- Windows users cannot use the %V specifier for strftime as it is not implemented in the OS. Following is a possible workaround function to get the ISO 8601:1988 weeknumber. Note that unlike the previous (20-Jan-2002) function, this function will also fix last week of the year to 01 whenever necessary. <?php // Get the week number in ISO 8601:1988 format // This helsp when %V is not working on your Win32 machine function getWeekNumber($day, $month, $year) { $week = strftime("%W", mktime(0, 0, 0, $month, $day, $year)); $yearBeginWeekDay = strftime("%w", mktime(0, 0, 0, 1, 1, $year)); $yearEndWeekDay = strftime("%w", mktime(0, 0, 0, 12, 31, $year)); // make the checks for the year beginning if($yearBeginWeekDay > 0 && $yearBeginWeekDay < 5) { // First week of the year begins during Monday-Thursday. // Currently first week is 0, so all weeks should be incremented by one $week++; } else if($week == 0) { // First week of the year begins during Friday-Sunday. // First week should be 53, and other weeks should remain as they are $week = 53; } // make the checks for the year end, these only apply to the weak 53 if($week == 53 && $yearEndWeekDay > 0 && $yearEndWeekDay < 5) { // Currently the last week of the year is week 53. // Last week of the year begins during Friday-Sunday // Last week should be week 1 $week = 1; } // return the correct ISO 8601:1988 week (in two digit format) return( substr('0'. $week, -2) ); } ?>

« previous php.notes (#93629) next »