pascal_ | Popop56 a écrit :
Avec ceci j'obtiens le premier jour de la semaine 19 (bon c'est pas bien grave mais je comprends pas trop)
|
Ah, je trouve le 21 mai qui est effectivement 20 semaines de plus que le 1er janvier.
Sinon il y a une fonction dans les commentaires sur php.net:
Code :
- // ******************************************************
- // Function that returns the dates for each day in a week
- // ******************************************************
- function week_dates($week,$year) {
- $week_dates = array();
- // Get timestamp of first week of the year
- $first_day = mktime(12,0,0,1,1,$year);
- $first_week = date("W",$first_day);
- if ($first_week > 1) {
- $first_day = strtotime("+1 week",$first_day); // skip to next if year does not begin with week 1
- }
- // Get timestamp of the week
- $timestamp = strtotime("+$week week",$first_day);
- // Adjust to Monday of that week
- $what_day = date("w",$timestamp); // I wanted to do "N" but only version 4.3.9 is installed :-(
- if ($what_day==0) {
- // actually Sunday, last day of the week. FIX;
- $timestamp = strtotime("-6 days",$timestamp);
- } elseif ($what_day > 1) {
- $what_day--;
- $timestamp = strtotime("-$what_day days",$timestamp);
- }
- $week_dates[1] = date("Y-m-d",$timestamp); // Monday
- $week_dates[2] = date("Y-m-d",strtotime("+1 day",$timestamp)); // Tuesday
- $week_dates[3] = date("Y-m-d",strtotime("+2 day",$timestamp)); // Wednesday
- $week_dates[4] = date("Y-m-d",strtotime("+3 day",$timestamp)); // Thursday
- $week_dates[5] = date("Y-m-d",strtotime("+4 day",$timestamp)); // Friday
- $week_dates[6] = date("Y-m-d",strtotime("+5 day",$timestamp)); // Saturday
- $week_dates[7] = date("Y-m-d",strtotime("+6 day",$timestamp)); // Sunday
- return($week_dates);
- }
|
J'ai rapidement testé, la première semaine de l'année est la 0 si j'ai bien compris...; Message édité par pascal_ le 30-10-2006 à 13:20:30
|