Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Convert to GMT DateTime

Tags:

sql

time

I want to convert my record entries from datetime+OFFSET to datetimeZ directly

(2008-05-11T15:30:00+2 ---> 2008-05-11T13:30:00Z) 

with SQL functions.

I need to implement this using MySql preferrably, not using stored procedures.

like image 294
Lici Avatar asked Oct 29 '25 05:10

Lici


1 Answers

Try this

To convert from GMT to local time:

select DATEADD(hour,DATEDIFF (hour, GETUTCDATE(), GETDATE()),MyGmtDateTime) as LocalDateTime

To convert from local time to GMT:

select DATEADD(hour,DATEDIFF (hour, GETDATE(), GETUTCDATE()),MyLocalDateTime) as GmtDateTime
like image 66
José Cláudio Avatar answered Oct 31 '25 18:10

José Cláudio



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!