Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to create Carbon object from this string: 2022-06-21T05:52:46.648533678Z?

How to create DateTime object with PHP from this string: 2022-06-21T05:52:46.648533678Z? There is nine numbers after ‘dot’, after seconds.

I tried to use next variants:

<?php
Carbon::createFromFormat('Y-m-d\TH:i:s.uP', '2022-06-21T05:52:46.648533678Z');
Carbon::createFromFormat('Y-m-d\TH:i:s.vP', '2022-06-21T05:52:46.648533678Z');

And always get an error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The timezone could not be found in the database

>Solution :

The format should be as follows to cope with the 9 numerics after the . PHP only can cope with 6 numerics so the ? are just place holders for anything

<?php
Carbon::createFromFormat('Y-m-d\TH:i:s.u???P', '2022-06-21T05:52:46.648533678Z');
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading