PHP Date Monate verrechnet sich

TMaske77

Ensign
Registriert
Jan. 2004
Beiträge
146
Ich wollte alle Montage eines Jahres ausgeben.

Ab dem 21.3.2011 ist die Ausgabe falsch und ich komme nicht dahinter warum dies so ist.

Hat jemand eine Idee??

Code
PHP:
for ($fw = 1; $fw < 53; $fw++)
{
    $x = $fw * 7;
    $y = date("w", (mktime(23, 59, 59,1,1,$Jahr)));
    $x = $x - $y + 1    $Datuma = sprintf ("%s", date("d.m.y", (mktime(23, 59, 59,1,1,$Jahr)+ 60*60*24*$x)));           
    echo "FW=".$fw." x=".$x. "y=".$y."   Datum=".$Datuma."<br>"; 
}

erzeugt folgende Ausgabe

FW=1 x=2y=6 Datum=03.01.11
FW=2 x=9y=6 Datum=10.01.11
FW=3 x=16y=6 Datum=17.01.11
FW=4 x=23y=6 Datum=24.01.11
FW=5 x=30y=6 Datum=31.01.11
FW=6 x=37y=6 Datum=07.02.11
FW=7 x=44y=6 Datum=14.02.11
FW=8 x=51y=6 Datum=21.02.11
FW=9 x=58y=6 Datum=28.02.11
FW=10 x=65y=6 Datum=07.03.11
FW=11 x=72y=6 Datum=14.03.11
FW=12 x=79y=6 Datum=21.03.11 --> noch richtig
FW=13 x=86y=6 Datum=29.03.11 --> falsch
FW=14 x=93y=6 Datum=05.04.11
FW=15 x=100y=6 Datum=12.04.11
FW=16 x=107y=6 Datum=19.04.11
FW=17 x=114y=6 Datum=26.04.11
FW=18 x=121y=6 Datum=03.05.11
FW=19 x=128y=6 Datum=10.05.11
FW=20 x=135y=6 Datum=17.05.11
FW=21 x=142y=6 Datum=24.05.11
FW=22 x=149y=6 Datum=31.05.11
FW=23 x=156y=6 Datum=07.06.11
FW=24 x=163y=6 Datum=14.06.11
FW=25 x=170y=6 Datum=21.06.11
FW=26 x=177y=6 Datum=28.06.11
FW=27 x=184y=6 Datum=05.07.11
FW=28 x=191y=6 Datum=12.07.11
FW=29 x=198y=6 Datum=19.07.11
FW=30 x=205y=6 Datum=26.07.11
FW=31 x=212y=6 Datum=02.08.11
FW=32 x=219y=6 Datum=09.08.11
FW=33 x=226y=6 Datum=16.08.11
FW=34 x=233y=6 Datum=23.08.11
FW=35 x=240y=6 Datum=30.08.11
FW=36 x=247y=6 Datum=06.09.11
FW=37 x=254y=6 Datum=13.09.11
FW=38 x=261y=6 Datum=20.09.11
FW=39 x=268y=6 Datum=27.09.11
FW=40 x=275y=6 Datum=04.10.11
FW=41 x=282y=6 Datum=11.10.11
FW=42 x=289y=6 Datum=18.10.11
FW=43 x=296y=6 Datum=25.10.11
FW=44 x=303y=6 Datum=31.10.11
FW=45 x=310y=6 Datum=07.11.11
FW=46 x=317y=6 Datum=14.11.11
FW=47 x=324y=6 Datum=21.11.11
FW=48 x=331y=6 Datum=28.11.11
FW=49 x=338y=6 Datum=05.12.11
FW=50 x=345y=6 Datum=12.12.11
FW=51 x=352y=6 Datum=19.12.11
FW=52 x=359y=6 Datum=26.12.11
Ergänzung ()

Als Plattform setze ich XAMPP 1.7.2! --> PHP Version 5.3.0 ein
 
Hallo,

ohne es genauer angesehen zu haben, würde ich spontan auf die Zeitumstellung tippen.

Aus der PHP-Doku:

the "yeer-week-weekday" format also works, at least whit strtotime().

exemple Saturday the 17 week in 2011:
PHP:
<?php echo date("Y-m-d", strtotime("2011-W17-6")) . "\n"; ?>
 
Code:
PHP Warning:  mktime(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Berlin' for 'CEST/2.0/DST' instead in /root/test.php on line 8

--> SommerZeit ist das Problem

Weil du 23:59:59 Uhr gewählt hast und im Sommer ab dem ersten "Fehler" umgestellt wird, landest du beim nächsten Tag.

PS: Nach Ende Oktober (also nach der nächsten Zeitumstellung) ists wieder richtig!

Code:
      1 <?php
      2 $Jahr = 2011;
      3 date_default_timezone_set('Europe/Berlin');
      4 for ($fw = 1; $fw < 53; $fw++)
      5 {
      6     $x = $fw * 7;
      7     $y = date("w", (mktime(0,0,0,1,1,$Jahr)));
      8     $x = $x - $y + 1;
      9     $Datuma = sprintf ("%s", date("d.m.y", (mktime(0,0,0,1,1,$Jahr)+ 60*60*24*$x)));
     10     echo "FW=".$fw." x=".$x. "y=".$y."   Datum=".$Datuma."<br>\n";
     11 }
     12 ?>
 
Zuletzt bearbeitet:
Zurück
Oben