Alex Lomia
Alex Lomia

Reputation: 7235

Carbon::parse("25/10/1980") throws an error

I'm facing an odd issue, Carbon::parse("25/10/1980") throws the following error:

Exception with message 'DateTime::__construct(): Failed to parse time string (25/12/1980) at position 0 (2): Unexpected character'

While having no problems whatsoever, if month (10) is swapped places with day (25) like this:

Carbon::parse("10/25/1980")

How should I parse the "d/m/Y" string?

Upvotes: 0

Views: 3941

Answers (2)

Matheus
Matheus

Reputation: 363

Try this:

Carbon::createFromFormat('d/m/Y', '25/10/1980');

Upvotes: 10

cartbeforehorse
cartbeforehorse

Reputation: 3487

This also works (dashes, not slashes)

Carbon::parse ('25-10-1980');

Upvotes: 3

Related Questions