Cátia Matos
Cátia Matos

Reputation: 930

DateTime::__construct(): Failed to parse time string (May 5 2022 12:00:00:AM) at position 20 (:): Unexpected character

I'm having the following error

ErrorException in /*/web/vendor/nesbot/carbon/src/Carbon/Carbon.php line 555:
DateTime::__construct(): Failed to parse time string (May 5 2022 12:00:00:AM) at position 20 (:): Unexpected character

In my list file,

{{ Carbon\Carbon::parse($r->AttendanceDate)->format('d/m/Y') }}         

    

The date in sql is a date time "2020-05-20 08:13:00.000"

I've tried some changes like format from DateTime to format to day, I've tried also to parse string and nothing worked.. I've seen some post with the same error but nothing result. Please help me

Upvotes: 2

Views: 11658

Answers (1)

miken32
miken32

Reputation: 42698

"Failed to parse time string (May 5 2022 12:00:00:AM)" is very clear. It can't parse that format. You can tell Carbon what format to expect using the Carbon::createFromFormat method.

Carbon::createFromFormat('M j Y h:i:s:A', 'May 5 2022 12:00:00:AM');

Format definitions are from PHP's DateTime::createFromFormat() method.

Upvotes: 4

Related Questions