开发者

SQL Server T-Sql Convert filetime to datetime

开发者 https://www.devze.com 2022-12-13 06:07 出处:网络
I need to convert a filetime field value to datetime format through t-sql in SQL Server I have applied following formula to do so which works absolutely fine for positive values (>0). But somehow thi

I need to convert a filetime field value to datetime format through t-sql in SQL Server

I have applied following formula to do so which works absolutely fine for positive values (>0). But somehow this formula does not work for negative values and it return null value.

SELECT LastModifiedTime,
       CASE WHEN LastModifiedTime <= 1 THEN NULL
       ELSE DATEADD(ms,
                    ((LastModifiedTime) / CAST(10000 AS bigint)) % 86400000,
                    DATEADD(day, (LastModifiedTime) / CAST(864000000000 AS bigint) - 109207, 0))
       END AS Expr1
FROM TableName

Sample value i had tried were:

  • -9094352270227314699 (negative value which did not work)
  • 129046581660000000 (p开发者_Python百科ositive value which works)


CASE WHEN LastModifiedTime <= 1 THEN NULL

It's doing what you told it to do.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号