Hallo Leute,
Ich habe auf meiner Website einen Kalender implementiert und ich möchte eben immer den nächsten Monat berechnen. Das hat auch immer geklappt aber als ich heute mal darauf geschaut habe ist mir aufgefallen dass nach März nicht April sondern Mai kommt.
Dann habe ich das mal ausprobiert isoliert mit dem Code :
$currentDate = Carbon::create(2025, 3, 31, 16, 31, 32, 'Europe/Berlin');
$nextMonth = $currentDate->copy()->addMonth(); echo "Nach addMonth: " . $nextMonth->toDateTimeString() . "\n";
$nextMonth->startOfMonth(); echo "Nach startOfMonth: " . $nextMonth->toDateTimeString() . "\n";
Und als Ergebnis kommt:
Nach addMonth: 2025-05-01 16:31:32 Nach startOfMonth: 2025-05-01 00:00:00
Ich habe das auch mal mit dem 30. ausprobiert und da klappt es:
$currentDate = Carbon::create(2025, 3, 30, 16, 31, 32, 'Europe/Berlin');
$nextMonth = $currentDate->copy()->addMonth(); echo "Nach addMonth: " . $nextMonth->toDateTimeString() . "\n";
$nextMonth->startOfMonth(); echo "Nach startOfMonth: " . $nextMonth->toDateTimeString() . "\n";
Das Ergebnis:
Nach addMonth: 2025-04-30 16:31:32 Nach startOfMonth: 2025-04-01 00:00:00
Kann sich das jemand erklären, funktioniert bei mir auch nicht mal mit anderen Methoden wie DateTime::add()
Und weiß jemand wie ich das auch anders umsetzen kann?
Vielen Dank im Vorraus