在SQL中将7位数的儒略日期转换为DateTime?

问题描述:

我在网上看到了很多例子,在SO上也看到了一些例子.但是,似乎没有一个适用于我的数据.以下是一些朱利安日期及其已知的转换值.

I have seen numerous examples on the web and a few here on SO. However, none seem to work for my data. Here are a few julian dates with their known converted values.

JUL | DateTime
2454522 | 2008-02-25 00:00:00.000
2454571 | 2008-04-14 00:00:00.000
2455713 | 2011-05-31 00:00:00.000

我已经尝试了这不起作用:

I have tried this which does not work:

DECLARE @JD int = 2454522
SELECT DATEADD(YEAR, @JD / 1000 - 1900, @JD % 1000 - 1)

它给了我这个:2455-06-06 00:00:00.000这显然是错误的.我在这里想念什么?感谢ind的进步.

It gives me this: 2455-06-06 00:00:00.000 which is obviously wrong. What am I missing here? Thanks ind advance.

在SQLServer中应该起作用的一种方法:

One approach that should work in SQLServer:

select @jd, dateadd(d,@jd - 2440588,'1970-01-01')

SQLFiddle 此处.

SQLFiddle here.