Convert .NET Ticks to SQL Server DateTime

后端 未结 7 890
攒了一身酷
攒了一身酷 2020-11-30 10:10

I am saving a TimeSpan (from .NET) value in my db as BIGINT in SQL Server (saving the Ticks property). I want to know how to convert this BIG

7条回答
  •  粉色の甜心
    2020-11-30 10:44

    I don't really know SQL Server, but today a colleague of mine had the same problem and I think I've found a solution like this:

    CAST(([ticks] - 599266080000000000) / 10000000 / 24 / 60 / 60 AS datetime)
    

    where 599266080000000000 is the ticks value for 01/01/1900 00:00:00.

提交回复
热议问题