TSQL - Conversion of Epcoh to Datetime

Convert Current UTC date to Epoch


SELECT DATEDIFF(s, '1970-01-01 00:00:00', GETUTCDATE())
SELECT DATEDIFF(s, '19700101', GETUTCDATE())


Convert Epoch to dateTime

select dateadd(ss, epoch, '19700101')

SELECT DATEADD(s, epoch, '1970-01-01 00:00:00')


Example
select dateadd(ss, 1394796484, '19700101')

SELECT DATEADD(s, 1393345800, '1970-01-01 00:00:00')

Comments

Popular posts from this blog

SSAS : A connection cannot be made to redirector. Ensure that 'SQL Browser' service is running. (Microsoft.AnalysisServices.AdomdClient). + Solution

SSIS Error : Unable to infer the XSD from the XML file. The XML contains multiple namespaces