I have bigInt: 635307578922100000
which I need to convert to DateTime
.
I've tried few ways to do this:
SELECT
DATEADD(S, CONVERT(bigint,635307578922100000) / 1000, CONVERT(DATETIME, '1-1-1970 00:00:00'))
and:
SELECT
DATEADD(ms, 635307578922100000 / 86400000, (635307578922100000 / 86400000) +25567)
While I found the codes above work with bigInts
like: 1283174502729
, with my bigInt I get the following error:
Msg 8115 ... Arithmetic overflow error converting expression to data type datetime.
Does anyone have any idea how to solve it?
Here are some calculations that can calculate the bigint to a datetime.
Result:
With a bit of tampering those datetimes can be truncated or rounded on the seconds.
I think it's in ticks (yields 2014-03-18 16:44:52.210). Here is solution:
This magic value 599266080000000000 is number of ticks between 0001-01-01 and 1900-01-01 calculated in PowerShell as follows:
Conversions are required, because DATEADD won't work with bigint (requires int). SQL Server DateTime is also limited to 1 January 1753.