-1

I know how to convert an epoch timestamp to a SQL server timestamp using DATEADD, but I am interested in a function that does the reverse of that.

Hank
  • 21
  • 1
  • 2

1 Answers1

2

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
Md. Suman Kabir
  • 5,243
  • 5
  • 25
  • 43