[Dates] problème fonction date
Bonjour,
j ai un problème pour l affichage de dates. Je veux afficher une période par semaine de mes dates et remonter dans le temps ...
vous pouvez m aider...
voici le code et ce que ca me donne il manque quelque chose pour prendre en compte l'année.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
| <?php
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("d/m/Y",$timestamp); // Monday
$week_dates[2] = date("d/m/Y",strtotime("+6 day",$timestamp)); // Sunday
return($week_dates);
}
//SEMAINE COURANTE
$semaine = date('W',time()-7*24*60*60);
$annee = date ('Y');
for ($i=0;$i<24;$i++)
{
$array = week_dates($semaine,$annee);
$_GET['numero']=$array[1]."-".$array[2];
$num = $_GET['numero'];
echo '<a href="result.php?id='.$num.'">'.$array[1]." au ".$array[2].'</a>'."<br>";
$semaine--;
}
?> |
affichage :
05/01/2009 au 11/01/2009
29/12/2008 au 04/01/2009
----problème à partir d'ici?????
29/12/1969 au 04/01/1970
29/12/1969 au 04/01/1970
29/12/1969 au 04/01/1970
29/12/1969 au 04/01/1970
29/12/1969 au 04/01/1970
29/12/1969 au 04/01/1970
29/12/1969 au 04/01/1970
29/12/1969 au 04/01/1970
29/12/1969 au 04/01/1970
29/12/1969 au 04/01/1970
29/12/1969 au 04/01/1970
29/12/1969 au 04/01/1970
29/12/1969 au 04/01/1970
29/12/1969 au 04/01/1970
29/12/1969 au 04/01/1970
29/12/1969 au 04/01/1970
29/12/1969 au 04/01/1970
29/12/1969 au 04/01/1970
29/12/1969 au 04/01/1970
29/12/1969 au 04/01/1970
29/12/1969 au 04/01/1970
29/12/1969 au 04/01/1970