# convert Julian date to Gregorian date

Discussion in 'ASP .Net' started by Sam, Apr 27, 2005.

1. ### SamGuest

How do I convert Julian Date to Calendar Date in ASP.Net 1.1 based on
following guideline found at Internet?

To convert Julian date to Gregorian date:

double JD = 2299160.5;

double Z = Math.Floor(JD+0.5);
double W = Math.Floor((Z - 1867216.25)/36524.25);
double X = Math.Floor(W/4);
double AA = Math.Floor(Z+1+W-X);
double BB = Math.Floor(AA+1524);
double CC = Math.Floor((BB-122.1)/365.25);
double DD = Math.Floor(365.25*CC);
double EE = Math.Floor((BB-DD)/30.6001);
double FF = Math.Floor(30.6001*EE);

double Day = BB-DD-FF;
double Month;
double Year;

if((EE-13) <= 12 && (EE-13) > 0)
Month = EE-13;
else
Month = EE-1;

if(Month == 1 || Month == 2)
Year = CC-4715;
else
Year = CC-4716;

Sam, Apr 27, 2005

2. ### Pete DavisGuest

I'm not sure what you're asking. I mean, this is pretty much the code for
it. I'd be surprised if you couldn't just copy and paste this into a C#
method and be done with it.

Simply pass "JD" as a parameter to the method and return Month Day and Year
as a DateTime, string, or whatever.

Pete

"Sam" <> wrote in message
news:...
> How do I convert Julian Date to Calendar Date in ASP.Net 1.1 based on
> following guideline found at Internet?
>
> To convert Julian date to Gregorian date:
>
> double JD = 2299160.5;
>
> double Z = Math.Floor(JD+0.5);
> double W = Math.Floor((Z - 1867216.25)/36524.25);
> double X = Math.Floor(W/4);
> double AA = Math.Floor(Z+1+W-X);
> double BB = Math.Floor(AA+1524);
> double CC = Math.Floor((BB-122.1)/365.25);
> double DD = Math.Floor(365.25*CC);
> double EE = Math.Floor((BB-DD)/30.6001);
> double FF = Math.Floor(30.6001*EE);
>
> double Day = BB-DD-FF;
> double Month;
> double Year;
>
> if((EE-13) <= 12 && (EE-13) > 0)
> Month = EE-13;
> else
> Month = EE-1;
>
> if(Month == 1 || Month == 2)
> Year = CC-4715;
> else
> Year = CC-4716;
>
>

Pete Davis, Apr 27, 2005