ove ove - 2 months ago 24
C# Question

Convert BigInt value in SQL to datetime in c#

I usually use the SQL function below to convert bigint in sql to datetime in SQL Server 2005.

DECLARE @datetime AS bigint, @day AS int, @ms AS int
SET @datetime = 129471410567460000
SET @ms = (@datetime / CAST(10000 AS bigint)) % 86400000
SET @day = @datetime / CAST(864000000000 AS bigint) - 109207
SELECT DATEADD(ms,@ms, DATEADD(day, @day, 0))


How do i do it using c# ? I am able to read in time value (129471410567460000) from the SQL server and want to convert to datetime. The datetime will be used in a c# application.

Cheers

ove ove
Answer

Solution is

DateTime.FromFileTimeUtc()
Comments