Consider the following query (in MSSQL 2008):
SELECT dateModified FROM SomeTable;
This returns floats in javascript format (milliseconds since 1970):
dateModified
============
1301598290687
1071003581343
1311951478593
How can I convert this to a datetime2 right in the select?
Using the formula from @Mikeal Eriksson's answer here.
I would convert the float to a bigint and then create the datetime:
select
DATEADD(MILLISECOND,
cast(dateModified as bigint) % 1000,
DATEADD(SECOND, cast(dateModified as bigint) / 1000, '19700101'))
from sometable
See SQL Fiddle with Demo
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With