Monday, April 5, 2010

C# method to convert Julian to Gregorian date

Hello there,

I was in urgent need to convert Julian date to Georgian for a application which reads data from DB2.

The following code was useful.

public static string JulianToDateTime(int julianDate)


int RealJulian = julianDate + 1900000;

int Year = Convert.ToInt32(RealJulian.ToString().Substring(0, 4));

int DoY = Convert.ToInt32(RealJulian.ToString().Substring(4));

DateTime dtOut = new DateTime(Year, 1, 1);

return dtOut.AddDays(DoY - 1).ToShortDateString();


Hope It Helps


No comments: