Board index » delphi » Looking for Julian date routines

Looking for Julian date routines

Does anyone have routines that will return the current date as
'day-of-year', a julian date like the US military uese.

Thanks

 

Re:Looking for Julian date routines


In article <695nsk$...@news3.his.com>, Darrel Davis <darr...@his.com>
writes

Quote
>Does anyone have routines that will return the current date as
>'day-of-year', a julian date like the US military uese.

>Thanks

I'm not sure what the US military use, not being a member myself and as
far as I can gather there are several permutations of 'julian dates'.
However you could try - www.sharry.demon.co.uk
--
Andrew James Johnson

Re:Looking for Julian date routines


 It'd be easy enough... Figure out the month, and add the days in
between....  (or subtract from 365 (I forget which one goes which way...))
But, in your function, you'd wanna use a case statement... (something like
this....)

function GetJulian(Day, Month: Integer): inter;
begin
  Result := 0;    <--  bad date....
  Case Month of
    1:  result := day;
    2:  result := 31 + day;
    3:  result := 31 + 28 + day;

    etc...

  12:  result := 31 + 28 + .... 31 + day;
  end;
  if Result = 0 then MessageBox(Application.Handle, 'Bad Date', 'Error',
MB_ICONERROR);
end;

  Or something to that effect....

--
Jason Wallace
SL Software
Dark...@SLSoftware.reno.nv.us
--
"We are Microsoft.  Resistance is Futile.  You will be Assimiliated."

Quote
Darrel Davis wrote in message <695nsk$...@news3.his.com>...
>Does anyone have routines that will return the current date as
>'day-of-year', a julian date like the US military uese.

>Thanks

Re:Looking for Julian date routines


There's a "Year 2000" article that covers a lot of the date
math functions, including Julian dates (I think) in the latest
Unofficial Newsletter for Delphi Users (UNDU).  It's a free
download; get it in the "Windows Help" format; there's also
an HTML version, but the HTML coding sometimes scrambles the
Pascal source code.
http://www.informant.com/delphi
--
============================================================
Rick Carter   carte...@email.uc.edu   rcar...@tso.cin.ix.net
============================================================

Re:Looking for Julian date routines


On 11 Jan 1998 12:59:43 GMT, carte...@news.ececs.uc.edu (Richard

Quote
Carter) wrote:
>There's a "Year 2000" article that covers a lot of the date
>math functions, including Julian dates (I think) in the latest
>Unofficial Newsletter for Delphi Users (UNDU).  It's a free
>download; get it in the "Windows Help" format; there's also
>an HTML version, but the HTML coding sometimes scrambles the
>Pascal source code.
>http://www.informant.com/delphi
>--
>============================================================
>Rick Carter   carte...@email.uc.edu   rcar...@tso.cin.ix.net
>============================================================

Here's what I use...

------------------------------------------------------------------------------

FUNCTION ymdtojul(y : INTEGER; m,d : BYTE) : LONGINT;

VAR temp : REAL;
    yr,mn,dy,d1 : word;

BEGIN
  IF (y < 1900) or (y > 2099) or NOT(M IN [1..12]) OR NOT(d IN
[1..31]) THEN
  BEGIN
    getdate(yr,mn,dy,d1);
    y := yr;
    m := mn;
    d := dy;
  END;
  temp := INT((m - 14.0) / 12.0);
  ymdtojul := TRUNC(d- 32075 +
                    INT(1461.0 * (y + 4800.0 + temp) / 4.0) +
                    INT(367.0 * (m - 2.0 - temp * 12.0) / 12.0) -
                    INT(3.0 * INT((y + 4900.0 + temp) / 100.0) /
4.0));
END;

{-------------------------------------------------------------------------}

PROCEDURE jultoymd(julian : LONGINT; VAR y : INTEGER; VAR m,d : BYTE);

VAR tempa,tempb : REAL;

BEGIN
  IF (julian < 0) THEN
  BEGIN
    y := 0;
    m := 0;
    d := 0;
    EXIT;
  END;
  tempa := julian + 68569.0;
  tempb := INT(4.0 * tempa / 146097.0);
  tempa := tempa - INT((146097.0 * tempb + 3.0) / 4.0);
  y := TRUNC(4000.0 * (tempa + 1.0) / 1461001.0);
  tempa := tempa - INT(1461.0 * y / 4.0) + 31.0;
  m := TRUNC(80.0 * tempa / 2447.0);
  d := TRUNC(tempa - INT(2447.0 * m / 80.0));
  tempa := INT(m / 11.0);
  m := TRUNC(m + 2.0 - 12.0 * tempa);
  y := TRUNC(100.0 * (tempb - 49.0) + y + tempa);
END;

----------------------------------------------------------------------------------

Re:Looking for Julian date routines


Quote
Darrel Davis wrote:

> Does anyone have routines that will return the current date as
> 'day-of-year', a julian date like the US military uese.

> Thanks

"Numerical Recipes in Pascal (or C or Fortran)"  by Press, et. al. has
such a program I believe.  Sincerely, R. Bullock

Re:Looking for Julian date routines


On 11 Jan 1998 12:59:43 GMT, carte...@news.ececs.uc.edu (Richard

Quote
Carter) wrote:
>There's a "Year 2000" article that covers a lot of the date
>math functions, including Julian dates (I think) in the latest
>Unofficial Newsletter for Delphi Users (UNDU).  It's a free
>download; get it in the "Windows Help" format; there's also
>an HTML version, but the HTML coding sometimes scrambles the
>Pascal source code.
>http://www.informant.com/delphi
>--
>============================================================
>Rick Carter   carte...@email.uc.edu   rcar...@tso.cin.ix.net
>============================================================

Here's what I use...

------------------------------------------------------------------------------

FUNCTION ymdtojul(y : INTEGER; m,d : BYTE) : LONGINT;

VAR temp : REAL;
    yr,mn,dy,d1 : word;

BEGIN
  IF (y < 1900) or (y > 2099) or NOT(M IN [1..12]) OR NOT(d IN
[1..31]) THEN
  BEGIN
    getdate(yr,mn,dy,d1);
    y := yr;
    m := mn;
    d := dy;
  END;
  temp := INT((m - 14.0) / 12.0);
  ymdtojul := TRUNC(d- 32075 +
                    INT(1461.0 * (y + 4800.0 + temp) / 4.0) +
                    INT(367.0 * (m - 2.0 - temp * 12.0) / 12.0) -
                    INT(3.0 * INT((y + 4900.0 + temp) / 100.0) /
4.0));
END;

{-------------------------------------------------------------------------}

PROCEDURE jultoymd(julian : LONGINT; VAR y : INTEGER; VAR m,d : BYTE);

VAR tempa,tempb : REAL;

BEGIN
  IF (julian < 0) THEN
  BEGIN
    y := 0;
    m := 0;
    d := 0;
    EXIT;
  END;
  tempa := julian + 68569.0;
  tempb := INT(4.0 * tempa / 146097.0);
  tempa := tempa - INT((146097.0 * tempb + 3.0) / 4.0);
  y := TRUNC(4000.0 * (tempa + 1.0) / 1461001.0);
  tempa := tempa - INT(1461.0 * y / 4.0) + 31.0;
  m := TRUNC(80.0 * tempa / 2447.0);
  d := TRUNC(tempa - INT(2447.0 * m / 80.0));
  tempa := INT(m / 11.0);
  m := TRUNC(m + 2.0 - 12.0 * tempa);
  y := TRUNC(100.0 * (tempb - 49.0) + y + tempa);
END;

----------------------------------------------------------------------------------

Re:Looking for Julian date routines


Quote
Darrel Davis wrote in message <695nsk$...@news3.his.com>...
>Does anyone have routines that will return the current date as
>'day-of-year', a julian date like the US military uese.

TDateTime variables will do what you want.  Just subtract
the date of interest (I use "Now" below) from the
Jan 1 TDateTime, which you can find using DecodeDate
and EncodeDate:

DecodeDate(Now, Year, Month, Day);   // Just to get the year
DayOfYear := 1 + TRUNC(Now - EncodeDate(Year,1,1,));

Add 1 since "Jan 1" - "Jan 1" above will return 0.

efg
_________________________________________________

Earl F. Glynn          EarlGl...@WorldNet.att.net
MedTech Research Corporation
Lenexa, KS  66219  USA

Re:Looking for Julian date routines


[This follow up was also send to author]
A human entity called "Darrel Davis" <darr...@his.com> send the message :

Quote
>Does anyone have routines that will return the current date as
>'day-of-year', a julian date like the US military uese.

Check out the dates section of the UDDF..

The Graphical Gnome (r...@ktibv.nl)
Sr. Software Engineer IT Department
-----------------------------------------
The Unofficial Delphi Developers FAQ
http://www.gnomehome.demon.nl/uddf/index.htm

Other Threads