Working with API which gives me datetime in "2022-11-02T21:00:00.0000000Z" format. I am trying to convert it using Carbon and throwing me an error.
$dateTime = "2022-11-02T21:00:00.0000000Z";
$dateUpdated = Carbon::createFromFormat('Y-m-d\TH:i:s', $dateTime);
Error from Carbon:
Error Parsing updated datetime with format Y-m-d\TH:i:s Carbon\Exceptions\InvalidFormatException: Trailing data in /usr/src/app/vendor/nesbot/carbon/src/Carbon/Traits/Creator.php:676
I am using Laravel 8.
CodePudding user response:
Try use Carbon::parse
$dateTime = "2022-11-02T21:00:00.0000000Z";
$dateUpdated = Carbon::parse($dateTime);
echo $dateUpdated ->format('Y-m-d H:i:s');