Carbon: Error converting ISO8601 format string

Created on 2 Sep 2015  路  5Comments  路  Source: briannesbitt/Carbon

When I try to do following

Carbon::createFromFormat('Y-m-dTH:i:s', '2015-01-01T01:02:03Z');

Following exception occurs

The timezone could not be found in the database Data missing 

The time string I'm trying to use is a valid ISO8601 string indicating UTC. Any idea what I'm doing wrong?

Most helpful comment

The implementation is based on http://php.net/manual/en/datetime.createfromformat.php

Your format is wrong.... "T" indicates a Timezone identifier.

I think you are good with just new Carbon('2015-01-01T01:02:03Z'); or Carbon::parse('2015-01-01T01:02:03Z');

All 5 comments

The implementation is based on http://php.net/manual/en/datetime.createfromformat.php

Your format is wrong.... "T" indicates a Timezone identifier.

I think you are good with just new Carbon('2015-01-01T01:02:03Z'); or Carbon::parse('2015-01-01T01:02:03Z');

Thank you :)

I think this would be helpful to have in the docs somewhere.

For anyone else who comes across this, you need to escape the T in the format string ('Y-m-d\TH:i:s'). But better yet, you can use the available constant DateTime::ISO8601 (see the docs).

@parkercameron you better don't use DateTime::ISO8601 because of the docs.

Note: This format is not compatible with ISO-8601, but is left this way for backward compatibility reasons. Use DateTime::ATOM or DATE_ATOM for compatibility with ISO-8601 instead.

Was this page helpful?
0 / 5 - 0 ratings