note 47435 added to function.date
| From: | burkard dot schemmel at gmx dot de | Date: | Tue, 16 Nov 2004 12:18:42 +0000 |
| Subject: | note 47435 added to function.date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-80587@lists.php.net to get a copy of this message | ||
Ever had trouble about german calculation of number of weeks in a certain year? Of course,
there's date("W"), which wil be correct according to ISO standard. But what to do if
you want to have a list of weeks in a certain year? If you use date("W"), your last week
of a year may be 1. Thats correct. But you also have to change the year then - e.g. December 31th
2002 is in week 1 of the year 2003!
This little script will help you out:
function getWeeksOfYear($aYear)
{
$arrWeek = array();
$ts = mktime(0,0,0,12,31,$aYear);
$ts2 = mktime(0,0,0,12,24,$aYear);
$lastkw = date ("W", $ts);
$lastyear = date ("Y", $ts);
$lastkw2 = date ("W", $ts2);
$lastyear2 = date ("Y", $ts2);
if ($lastkw == "1") $lastyear = $lastyear+1;
for($i=1;$i<=$lastkw2;$i++)
{
$arrWeek[$i-1]['kw'] = $i;
$arrWeek[$i-1]['year'] = $lastyear2;
}
$arrWeek[$i]['kw'] = $lastkw;
$arrWeek[$i]['year'] = $lastyear;
return $arrWeek;
}
More information available here: http://www.salesianer.de/util/kalfaq.html#B3
----
Manual Page -- http://www.php.net/manual/en/function.date.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+47435
Delete -- http://master.php.net/manage/user-notes.php?action=delete+47435&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+47435&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+47435&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+47435&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+47435&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+47435&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+47435&report=yes
Search -- http://master.php.net/manage/user-notes.php