note 49457 added to function.date
| From: | agnodotnospamatnetsidedotde at osu1 dot php dot net | Date: | Fri, 28 Jan 2005 15:19:43 +0000 |
| Subject: | note 49457 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-84126@lists.php.net to get a copy of this message | ||
Calculus of weeks in a year.
Since there is date("W") many still seem to have a problem regarding how many weeks there
are in an year. Some rather complex solutions have been shown here.
It's defined, that a week which begins in december and ends in january the following year
belongs to the year where most of its days lie. Therefore a week with at least 4 days in december is
the last week of that year and a week with at least 4 days in january is the first week in the new
year.
This concludes, that the last week of a year always contains the 28th day of december. So if you
take date("W") on that day of a given year you always get the correct number of weeks for
that year.
The other end of that definition is that the 4th day of january always lies in the first week of a
year.
I hope this solves a lot of confusion.
(For those asking what all this fuzz about counting weeks is about: normally theres 52 weeks in a
year but sometimes its 53 weeks in a year)
I wrote it down as a function, but as this is rather trivial one might consider using the date(...)
only.
function weeks($year) {
return date("W",mktime(0,0,0,12,28,$year));
}
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+49457
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+49457&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+49457&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+49457&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+49457&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+49457&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+49457&report=yes
Search -- http://master.php.net/manage/user-notes.php