SQL - Convert DateTime to Local Time from UTC It is a good idea to store times in a database as UTC so that changing time zones do not cause problems. But you will want to display this in your application as local time. To convert a SQL datetime from UTC to local time: DATEADD(MILLISECOND,DATEDIFF(MILLISECOND,getutcdate(),GETDATE()), MYDATETIME) And back from local time to UTC time: DATEADD(second, DATEDIFF(second, GETDATE(), GETUTCDATE()), MYDATETIME)
Created By: amos 2/22/2016 9:44:52 AM Updated: 2/22/2016 9:51:20 AM
|
|