note 93314 deleted from function.date by derick
| From: | derick@php.net | Date: | Sun, 15 Aug 2010 18:45:25 +0000 |
| Subject: | note 93314 deleted from function.date by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-171715@lists.php.net to get a copy of this message | ||
Note Submitter: Sean Proctor
----
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;
}
?>