Hi @reuvygroovy ,
The key here is "UTCFILETIME" which contains a 64-bit value representing the number of 100-nanosecond intervals since January 1, 1601 (UTC).
If you are on SQL Server 2008 or later, you could refer below:
DECLARE @ts as bigint = 132500977560844177
SELECT DATEADD(nanosecond,@ts % 600000000,
DATEADD(minute,@ts / 600000000, cast('16010101' as datetime2(7))))
Output:
2020-11-17 14:42:00.3608442
If you are on an earlier version, or if there is another reason that you have to use datetime, you could refer below:
Declare @filetime_to_convert bigint
Set @filetime_to_convert = 132500977560844177
SELECT DATEADD(ms, ((@filetime_to_convert-47966688000000000) % 600000000)/1000000,
DATEADD(minute,(@filetime_to_convert-47966688000000000) / 600000000, '17530101'))
Output:
2020-11-17 14:42:00.360
The magic value 47966688000000000 is the number of FILETIME units between 1601-01-01 and 1753-01-01. The breakdown in minutes and milliseconds (ms) is to prevent that the value overflows the maximum value of int (which would throw a runtime error for the function DateAdd()).
Reference:Convert BIGINT Timestamp to a Datetime???
Best regards
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Hot issues November--What can I do if my transaction log is full?
Hot issues November--How to convert Profiler trace into a SQL Server table