note 93314 modified in function.date by danbrown

From: Date: Wed, 02 Sep 2009 21:52:25 +0000
Subject: note 93314 modified in function.date by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-160181@lists.php.net to get a copy of this message
For the week number for weeks starting on Sunday: <?php function week_of_year($month, $day, $year) { $day_of_year = date('z', mktime(0, 0, 0, $month, $day, $year)); /* Days in the week before Jan 1. If you want weeks to start on Monday make this (x + 6) % 7 */ $days_before_year = date('w', mktime(0, 0, 0, 1, 1, $year)); $days_left_in_week = 7 - date('w', mktime(0, 0, 0, $month, $day, $year)); /* find the number of weeks by adding the days in the week before the start of the year, days up to $day, and the days left in this week, then divide by 7 */ return ($days_before_year + $day_of_year + $days_left_in_week) / 7; } ?> --was-- For the week number for weeks starting on Sunday: function week_of_year($month, $day, $year) { $day_of_year = date('z', mktime(0, 0, 0, $month, $day, $year)); /* Days in the week before Jan 1. If you want weeks to start on Monday make this (x + 6) % 7 */ $days_before_year = date('w', mktime(0, 0, 0, 1, 1, $year)); $days_left_in_week = 7 - date('w', mktime(0, 0, 0, $month, $day, $year)); /* find the number of weeks by adding the days in the week before the start of the year, days up to $day, and the days left in this week, then divide by 7 */ return ($days_before_year + $day_of_year + $days_left_in_week) / 7; } http://php.net/manual/en/function.date.php

« previous php.notes (#160181) next »