Reputation: 23
$value="Mar 10 2016 09:12:03:000AM";
return Carbon::createFromFormat('Y-m-d H:i:s.u0', $value);
Please will someone please tell me how to use Carbon to convert this date to that format.
I'm getting: InvalidArgumentException in Carbon.php line 425: Unexpected data found. Unexpected data found. The separation symbol could not be found Unexpected data found. The format separator does not match Trailing data
Upvotes: 2
Views: 7608
Reputation: 241
$value="Mar 10 2016 09:12:03:000AM";
Carbon::parse($value)->format('Y-m-d H:i:s.u0');
Use parse method to instantiate the $value string as carbon object and then you can use any of the helper functions available in Carbon Library. Refer to the given link :: http://carbon.nesbot.com/docs/#api-formatting.
Upvotes: 0
Reputation: 941
For detail about how to carbon module used please visit on link Carbon Docs
In controller declare use Carbon\Carbon;
$value="Mar 10 2016 09:12:03:000AM";
return Carbon::parse($value);
Upvotes: 0
Reputation: 1064
use carbon like
$value="Mar 10 2016 09:12:03:000AM";
return \Carbon\Carbon::parse($value)->format('Y-m-d H:i:s.u0');
Upvotes: 2