## 2 replies

Last post Oct 24, 2007 09:28 PM by fahiemulleh

Member

131 Points

91 Posts

### Julian Date Conversion

Hi,

Can anyone give me the code or at least algorithm to convert Julian Date to C# DateTime and vice versa?

Thanks

All-Star

44577 Points

13653 Posts

MVP

### Re: Julian Date Conversion

Have a look at

• http://www.codeproject.com/datetime/dateclass.asp
• http://www.codeproject.com/datetime/exceldmy.asp
Click "Mark as Answer" on the post that helped you.
This earns you a point and marks your thread as Resolved so we will all know you have been helped.
FAQ on the correct forum http://forums.asp.net/p/1337412/2699239.aspx#2699239

Member

131 Points

91 Posts

### Re: Julian Date Conversion

Lot of thanks TATWORTH. I have found the way to do it. The above links had C++ code where julian conversions were performed. I changed it a little to do it in C#. I am pasting my C# code here, so that it others may directly find these conversions.

```public static long ConvertToJulian( DateTime dt)
{
int m = dt.Month;
int d = dt.Day;
int y = dt.Year;

if(m < 3)
{
m = m + 12;
y=y-1 ;
}
long jd = d + (153 * m - 457) / 5 + 365 * y + (y / 4) - (y / 100) + (y / 400) + 1721119;
return jd;
}
public static DateTime ConvertFromJulian(int m_JulianDate)
{

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;
}```

Thanks again.

fahiem