# Julian Date to mm/dd/yyyy • ### Question

• User493093417 posted

Hi,

I want to convert julian date both 5 and 6 digit.I found two snippets but they dont help me.They are erring out.For example 105166,105157 etc.

private DateTime ConvertJulianToDateTime(object jDate)

{

DateTime date;

double dblA, dblB, dblC, dblD, dblE, dblF;

double dblZ, dblW, dblX;

int day, month, year;

try

{

double julianDate = Convert.ToDouble(jDate);

dblZ = Math.Floor(julianDate + 0.5);

dblW = Math.Floor((dblZ - 1867216.25) / 36524.25);dblX = Math.Floor(dblW / 4);

dblA = dblZ + 1 + dblW - dblX;

dblB = dblA + 1524;

dblC =
Math.Floor((dblB - 122.1) / 365.25);

dblD = Math.Floor(365.25 * dblC);

dblE = Math.Floor((dblB - dblD) / 30.6001);

dblF = Math.Floor(30.6001 * dblE);

day = Convert.ToInt32(dblB - dblD - dblF);if (dblE > 13)

{

month =
Convert.ToInt32(dblE - 13);

}

else

{

month =
Convert.ToInt32(dblE - 1);

}

if ((month == 1) && (month == 2))

{

year =
Convert.ToInt32(dblC - 4715);

}

else

{

year =
Convert.ToInt32(dblC - 4716);

}

date =
new DateTime(year, month, day);return date;

}

catch (ArgumentOutOfRangeException ex)

{

date =
new DateTime(0);

}

catch (Exception ex)

{

date =
new DateTime(0);

}

return date;

}

public static DateTime ConvertFromJulian(object jDate)

{

int m_JulianDate = Convert.ToInt32(jDate);

long L = m_JulianDate + 68569;

long N = (long)((4 * L) / 146097);

L = L - ((long)((146097 * N + 3) / 4));

long I = (long)((4000 * (L + 1) / 1461001));

L = L - (long)((1461 * I) / 4) + 31;

long J = (long)((80 * L) / 2447);

int Day = (int)(L - (long)((2447 * J) / 80));

L = (long)(J / 11);

int Month = (int)(J + 2 - 12 * L);

int Year = (int)(100 * (N - 49) + I + L);

DateTime dt = new DateTime(Year, Month, Day);return dt;

}