note 38661 added to function.strftime

From: Date: Thu, 01 Jan 2004 23:07:59 +0000
Subject: note 38661 added to function.strftime
Groups: php.notes 
Request: Send a blank email to php-notes+get-62762@lists.php.net to get a copy of this message
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) ); } ?> ---- Manual Page -- http://www.php.net/manual/en/function.strftime.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38661 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38661&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38661&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#62762) next »