开发者

Using cast or convert to convert negative int values to datetime in SQL Server

开发者 https://www.devze.com 2023-01-22 12:42 出处:网络
I have some negative integer values which are an offset from the default 1-1-1900 date. I have to get the datetime values from these. How can I do this.

I have some negative integer values which are an offset from the default 1-1-1900 date. I have to get the datetime values from these. How can I do this.

Example:

If I do:

SELECT convert(datetime, 53691) as Calc

OR

SELECT cast(53691 as datetime)

I get: 2047-01-01 00:00:00.000

What I need is that If I do:

SELECT convert(datetime, -53691) as Calc

OR

SELECT cast(-53691 as datetime)

I should get something like:

1开发者_Python百科753-01-01 00:00:00.000


-53690 would be 1753-01-01. -53691 takes you out of the range of the datetime data type (which doesn't support dates before 1753). Casting -53690 works as your other examples do.

0

精彩评论

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