mydoglixu
mydoglixu

Reputation: 944

Why is my date wrong with Carbon::createFromFormat()?

When I create the Carbon object from an existing string, it is making a completely wrong date out of it.

$dateString = "2022-04-01 21:24:00";
$carbon = Carbon::createFromFormat("Y-m-d H:i:s", $dateString);
echo $carbon->format("Y-m-d H:i:s");

and this outputs:

2023-12-01 21:12:00

Totally lost here. This doesn't make sense.

*Edit: Nevermind. I am an idiot and my format in the real code was "Y-m-d H:m:s"

Upvotes: 0

Views: 1610

Answers (1)

R4ncid
R4ncid

Reputation: 7139

I think that the code that you post it's not what you are using it seems month is using minutes

so 24 as month become 12 of the next year

probably you are using "Y-m-d H:m:s" instead of "Y-m-d H:i:s"

Upvotes: 2

Related Questions