Reputation: 12025
I have incoming string date:
$date = '09.04.1981';
I tried t format this date in DATE (mysql), so I do:
return Carbon::createFromFormat('Y-m-d', $date);
It returns me an exception:
"Unexpected data found.\r\nUnexpected data found.\r\nTrailing data"
Upvotes: 0
Views: 2049
Reputation: 8178
Carbon is finicky like this. Is the field currently set as a date in the model, or casted as such? This sometimes yields this error. Here's the doc section that might relate:
When a column is considered a date, you may set its value to a UNIX timestamp, date string (Y-m-d), date-time string, and of course a DateTime / Carbon instance, and the date's value will automatically be correctly stored in your database:
Not sure if this is going that far, based on your question though. You may also be able to add a format to the end to test. IE
return Carbon::createFromFormat('d.m.Y', $date)->format('your format of choice')
Also, from comments, check that the format is correct against what you are asking for -- if the wrong format, it will provide too much info and trigger the error above. Make sure you have ('d.m.y', $date)
in the method as above.
If you are looking to convert, try: Carbon::parse($date)->format('Y-m-d')
Upvotes: 2