Quantcast
Channel: Delphi Forum - Delphi Programming Kings of Code - Delphi Programming
Viewing all articles
Browse latest Browse all 173

Calculate Julian Date From Date

$
0
0
I have you Julian date since I can remember, I translated this from one of my Clipper functions and use it still today
Julian day is the continuous count of days since the beginning of the Julian Period used primarily by astronomers, based on the start of the gregorian calander 1 January 4713 BC.
This is the safest and most reliable way to compare dates that I have found.

function DateToJulianDay(ADate: TDateTime): Integer;
var
   Tmp1, Tmp2, Tmp3, Tmp4: Integer;
   AYear, AMonth, ADay: Word;
begin
   DecodeDate(ADate, AYear, AMonth, ADay);
   if AMonth > 2 then begin
      Tmp1 := AMonth - 3;
      Tmp2 := AYear;
   end else begin
      Tmp1 := AMonth + 9;
      Tmp2 := AYear - 1;
   end;
   Tmp1 := (Tmp1 * 153) + 2;
   Tmp3 := (Tmp2 div 100) * 146097;
   Tmp4 := (Tmp2 mod 100) * 1461;
   Result := (Tmp1 div 5) + (Tmp3 div 4) + (Tmp4 div 4) + ADay + 1721119;
end;

Usage :
   DateToJulianDay(Date());



 

Viewing all articles
Browse latest Browse all 173

Trending Articles