note 43943 deleted from function.date by kennyt
| From: | kennyt@php.net | Date: | Sun, 18 Jul 2004 17:04:50 +0000 |
| Subject: | note 43943 deleted from function.date by kennyt | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-73495@lists.php.net to get a copy of this message | ||
Note Submitter: zach@crito.org
----
riviere_gh at yahoo dot fr includes a useful date to week function, below. Seems to me that it needs
one minor change, or else it might correct the week incorrectly in some cases.
Change the function:
<?
function dateToSemaine($date){
$annee=date('Y',$date);
$datePremier="1/1/$annee";
$datePremier=strtotime($datePremier);
$joursNum=date('w',$datePremier)-2;
$nbJour=date('z',$date);
$semaine=intval(($nbJour+$joursNum)/7);
return $semaine+1;
}
?>
So that it looks like this:
<?
function dateToSemaine($date){
$annee=date('Y',$date);
$datePremier="1/1/$annee";
$datePremier=strtotime($datePremier);
$joursNum=date('w',$datePremier)-2;
$nbJour=date('z',$date)+1;
$semaine=intval(($nbJour+$joursNum)/7);
return $semaine+1;
}
?>
This makes sense, because the date function counts the day of year beginning from 0, so we have to
add one to line 6 so that the function recognizes day 1 as day 1 rather than day 0.
After making this change, the function can correctly return the number of weeks in January 2005.