Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL function to convert UTC Time String to DATETIME

Tags:

mysql

Is there any MYSQL function available to convert UTC Time String with TimeZone to DATETIME?

Ex: 2013-05-16T13:15:30Z

Cheers;

like image 680
Kapila Avatar asked Oct 21 '22 10:10

Kapila


1 Answers

you can use convert_tz directly on that timestamp:

select T,
  cast(T as datetime),  -- to cast 
  convert_tz(T, '+00:00', '+08:00')   -- to convert to local time
from 
  (select '2013-05-16T13:15:30Z' T) D

Depending upon your MySQL configuration you may be able to use @@session.time_zone to make the above +08:00 less static

like image 138
gillyspy Avatar answered Oct 24 '22 19:10

gillyspy