|
|
Question : T-SQL Convert Julian Date to Standard Date Format
|
|
Hello,
Could someone tell me how what the syntax is to convert a Julian date to a regular date format in SQL? Thanks.
d-
|
Answer : T-SQL Convert Julian Date to Standard Date Format
|
|
Are you sure it's a Julian date and not Julian Date number? Most people easily confuse the two. If it is a Julian Day Number, then this formula will always work;
dateadd(dd, (JDN-2415021), convert(datetime, '1900-01-01',103)), where JDN is the Julian Day Number you're trying to convert.
For 27 Aug 2003, you have a JDN of 2452879;
dateadd(dd, (2452879-2415021), convert(datetime, '1900-01-01',103)) will return 27 Aug 2003
If you need a number of years before 1900, simply subtract the number of DAYS to the year you want your data from 2415021, which I've used as a constant for the date 01 Jan 1900. For example, if your base date was 01-01-1890, then your formula would look like;
dateadd(dd, (JDN-2411369), convert(datetime, '1890-01-01',103)), where 3652 days have been subtracted from 2415021. (1 Jan 1890 occurred 3652 days before 01 Jan 1900, including leap years)
|
|
|
|
|