Frage

I have a Julian date of 41348 and Excel converts this Julian date to 3/15/2013. Do you know the logic Excel uses to calculate the calender date? I need this same logic to convert Julian dates to calender dates in SQL Server.

War es hilfreich?

Lösung

41348 is not julian date. Excel needs to use a formula to convert a julian date to a proper date. 183349 is an example of a julian date. 41348 is simply the number of days passed after 01/01/1900.

You can add those number of days to 01/01/1900, if I recall correctly, in SQL server to get the desired results.

EDIT: Yup, use DATEADD. Add a column with 01/01/1900

UPDATE Table
SET NewDate = DATEADD(Days, RawDate-2, '01/01/1900')

You need to remove 1 from the RawDate since 1 corresponds to 01/01/1900 and another 1 apparently I'm not sure where, but investigating.

On my SQL Server2008R2, apparently it considers 1900 to be a non-leap year. There goes the additional 1 to remove!

Andere Tipps

I hope 41348 julian date is not equl to "3/15/2013"

The first two digits are year and the next 3 digits represents for date 348 means Dec 14th.

I have done the same with below expression in Sql.

Select DATEADD(day, CAST(RIGHT('41348',3) AS int) - 1, CONVERT(datetime, LEFT('41348',2) + '0101', 112))

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top