[Solved] How do I convert a SQL server timestamp to an epoch timestamp? [duplicate]


You can do it using DATEDIFF function like below :

select DATEDIFF(s, '1970-01-01 00:00:00', '2017-11-20 23:12:02.000') as EpochTimeStamp

Output :

EpochTimeStamp
--------------
1511219522

You know already how can we get back the original date :

SELECT DATEADD(ss, 1511219522, '19700101') as OriginalDate

OriginalDate
-----------------------
2017-11-20 23:12:02.000

solved How do I convert a SQL server timestamp to an epoch timestamp? [duplicate]