sql server 2005 - SQL: Convert GMT in seconds to DateTime -


i have table 2 columns of gmt time in seconds, , offset in minutes this:

  select top 1 starttime, offset mytable;   1247242537  -420 -- example 

what sql function can use convert datetime in yyyy-mm-dd hh:mm:ss timestamp? sql using sql server 2005.

this should it, assuming epoch date 1/1/1970 (usually gmt seconds, need confirm)

select dateadd(ss,1247242537+(-420*60),'1/1/1970')   == >  2009-07-10 09:15:37.000 

for code, use

select dateadd(ss,starttime+(offset*60),'1/1/1970') thetime mytable 

be sure find test cases make sure epoch date expected. basically, gmt time number of seconds past 1/1/1970 12:00am, dateadd handles part. offset number of minutes different gmt, multiply 60 seconds , adjust value dateadd accordingly


Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -