Petro Gromovo
Petro Gromovo

Reputation: 2241

I got Not enough data available error with Carbon createFromFormat method

I try to parse with carbon datetime value in sstring as "2020-09-17T14:08:59Z", but with format :

Carbon::createFromFormat($stringData,'Y-m-d H:i:s' )

I got error :

Not enough data available to satisfy format {"exception":"[object] (Carbon\\Exceptions\\InvalidFormatException(code: 0): The format separator does not match

Which format have I to use ?

Thanks in advance!

Upvotes: 2

Views: 5408

Answers (1)

KyleK
KyleK

Reputation: 5121

Wrong parameters order, and wrong format (\T instead of space to match your separator, and e to get the timezone)

Carbon::createFromFormat('Y-m-d\TH:i:se', $stringData)

Or you can simply let Carbon find out the format:

Carbon::parse($stringData)

Upvotes: 7

Related Questions