I have the following table with epch unix datetime stamps. Can someone let me know if there is SQL query or function that will allow me to convert / replace the the UNIX EPOCH time to SQL format
Asked
Active
Viewed 466 times
-3
-
3Far too much rep to make no attempt - a trivial search would find suggestions – SMor Mar 15 '20 at 22:58
-
1And, of course, the duplicate posting on [msdn](https://social.msdn.microsoft.com/Forums/sqlserver/en-US/287c0194-4b96-432d-8a48-4fd8b379e249/how-to-query-unix-time-stamp-in-sql?forum=transactsql) to waste efforts. – SMor Mar 15 '20 at 23:03
1 Answers
0
An epoch timestamp represents the number of seconds elapsed since January 1st, 1970. In SQL Server, you can use dateadd()
to perform this computation:
dateadd(second, start_timeslot_unix, '19700101') start_timeslot_datetime
If your epochs are expressed in milliseconds instead of seconds, then: dateadd(second, start_timeslot_unix / 1000, '19700101')
.

GMB
- 216,147
- 25
- 84
- 135
-
For that second scenario, `dateadd(millisecond, start_timeslot_unix, '1970-01-01')` also works. – Ben Thul Mar 16 '20 at 01:09