/** * date('W') liefert für uns die falsche Wochennummer. Wir wollen nach ISO 8601:1988 * (erste Woche = Woche mit mindestens 4 Tage des neuen Jahres * @param timestamp $date * @return int */ function getWeekNr($date){ //Windows kann nicht alle Formatierbefehle. Darum muss die Woche nach ISO 8601:1988 Format anderst hergeholt werden //Version für Windows: if (stristr(PHP_OS, "win")<>false){ return getWeekNumber(date('j', $date), date('n', $date), date('Y', $date)); } else { //Version für Unix: return (Integer) strftime('%V', $date); } } // [url]http://theserverpages.com/php/manual/en/function.strftime.php[/url] // 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) ); }