Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

nabeel0489's avatar

Laravel parsing date incorrectly

I have used tinker and tried to check why my front end display is showing March if the month is Feb.

This was working till yesterday. It seems to pick up correct months for any other months in future or past.

can anyone let me know why I see march?

$date = Carbon\Carbon::createFromFormat('m-Y', "02-2025")->setTimezone('GMT') = Carbon\Carbon @1740825728 {#6258 date: 2025-03-01 10:42:08.0 +00:00, }

$date->format('F Y') = "March 2025"

0 likes
2 replies
tykus's avatar
tykus
Best Answer
Level 104

When you don't specify the individual date and time parts, Date uses the current values - today is 29th, but there is no 2025-02-29, so you get 2025-03-01 (because that is the day after February 28th).

You can reset all of the values using ! in the formatter; like this giving a Carbon instance at the beginning of the month

$date = Carbon\Carbon::createFromFormat('!m-Y', "02-2025")->setTimezone('GMT')
2 likes

Please or to participate in this conversation.