在SQL中将7位数的儒略日期转换为DateTime? [英] Convert 7 digit Julian Date to DateTime in SQL?
本文介绍了在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.
这篇关于在SQL中将7位数的儒略日期转换为DateTime?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文