I need to SELECT a ISO 8601 Date.
DATE_FORMAT(date, '%Y-%m-%dT%TZ')
This produces something like
2013-11-13T15:47:530Z
But I need it with the offset instead of Z value:
2013-11-13T15:47:53+02:00
How can I do this with plain MySQL ?
You need to store the timezone as an extra column in DB. I do not know any DB that stores datetime with timezone/offset.
Or store the date as string in ISO 8601 format with offset..
Edit: I stand somewhat corrected, with some newer databases it is possible!
Seems to actually be somewhat standard SQL99.
Not for Mysql. Version 5.6.
I do find consolation in the fact that the correction came from myself ;-)
his snippet should work for iso 8601 without milis, zulu time is also not supported:
select IF(
LENGTH(value) < 23,
STR_TO_DATE(value,'%Y-%m-%dT%TZ'),
CASE SUBSTRING(value from 20 for 1)
WHEN '+' THEN
DATE_ADD(
STR_TO_DATE(SUBSTRING(value from 1 for 19),'%Y-%m-%dT%TZ'),
INTERVAL SUBSTRING(value from 21 for 2) HOUR)
WHEN '-' THEN
DATE_SUB(
STR_TO_DATE(SUBSTRING(value from 1 for 19),'%Y-%m-%dT%TZ'),
INTERVAL SUBSTRING(value from 21 for 2) HOUR
)
END
)
from THE_NAMESPACE.THE_TABLE.THE_COLUMN as value;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With