MSSQL - Convert milliseconds since 1970 to datetime2
2 answers
Using @Mikeal Eriksson's formula answer here .
I would convert the float to bigint and then create the date and time:
select
DATEADD(MILLISECOND,
cast(dateModified as bigint) % 1000,
DATEADD(SECOND, cast(dateModified as bigint) / 1000, '19700101'))
from sometable
+8
source to share
Oracle example - replace to_date () with eqivalent:
SELECT (1301598290687/60/60/24/1000) as Days
, to_date('01-01-1970','dd-mm-yyyy') as start_date
, to_date('01-01-1970','dd-mm-yyyy')+(1301598290687/60/60/24/1000) as converted_date
FROM dual
/
DAYS START_DATE CONVERTED_DATE
---------------------------------------------------------
15064.7950310995 1/1/1970 3/31/2011 7:04:51 PM
Create a double table:
CREATE TABLE DUAL
(
DUMMY VARCHAR(1)
)
GO
INSERT INTO DUAL (DUMMY)
VALUES ('X')
GO
-1
source to share