
September 8, 2009 09:28 by
OMR
Unixtime is 32-bit integer. It’s a second counter. A problem is converting datetime to unix time on mssql server. This solution convert unixtime to datetime. For a more information for Unix Time by wikipedia.
Declare @UnixTime int
Set @UnixTime = 1219366020
Select dateadd(ss,@UnixTime,'1970-01-01')
To Function:
Create Function fn$UnixTimeToDatetime(@UnixTime int)
Returns Datetime
Begin
Return dateadd(ss,@UnixTime,'1970-01-01')
End
Go
Usage:
Select dbo.fn$UnixTimeToDatetime(1219366020) As DateAndTime
25982bd4-728e-4af7-ab38-b9ab1d6db4b6|0|.0