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

SQL Server MDS : How to Know Actual MDS Table name for Model Entity and Column name for the Attribute

SSRS : [Teradata Database] 3939 There is a mismatch between the number of parameters specified and the number of parameters required.

SSAS Error : XML parsing failed at line 1, column 0: A document must contain exactly one root element