/* USE below script to Convert epoch to human-readable date and vice versa*/
--GET current Unix epoch time
SELECT Datediff(second, '1970-01-01', Getdate()) AS [Current Unix Epoch Time]
go
--Convert epoch to human-readable date
DECLARE @UNIXEPOCHTIME BIGINT =Datediff(second, '1970-01-01', Getdate())
SELECT Dateadd(second, CASE
WHEN Len(@UNIXEPOCHTIME) = 13 THEN
@UNIXEPOCHTIME / 1000
ELSE @UNIXEPOCHTIME
END, '1970-01-01') AS CURRENTTIME
/* Below is the output of the above query */
/* Thank you,
Narasimha
*/
--GET current Unix epoch time
SELECT Datediff(second, '1970-01-01', Getdate()) AS [Current Unix Epoch Time]
go
--Convert epoch to human-readable date
DECLARE @UNIXEPOCHTIME BIGINT =Datediff(second, '1970-01-01', Getdate())
SELECT Dateadd(second, CASE
WHEN Len(@UNIXEPOCHTIME) = 13 THEN
@UNIXEPOCHTIME / 1000
ELSE @UNIXEPOCHTIME
END, '1970-01-01') AS CURRENTTIME
/* Below is the output of the above query */
/* Thank you,
Narasimha
*/
No comments:
Post a Comment