Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Julian Date Function

432 views
Skip to first unread message

Rick Roen

unread,
Nov 10, 1998, 3:00:00 AM11/10/98
to
Simon,

Here is a code snippet that I use to calculate the Julian date for encoding
into a shipping label.

This will set the JulianDate variable to the number of days since the
beginning of the year. I think there may be other formats that are used,
but you may be able to extrapolate how to get them from this code.

I setup the JulianDate as a string since I needed it in a "xxx" format. You
may need it as an integer, but that would be easy to change.

Rick


procedure GetJulianDate(var JulianDate: String);
var
year,month,day, DaysElapsed: word;
Jan1: TDateTime;
begin
JulianDate := '';
decodeDate(DM1.TShipWtDATE.AsDateTime,year,month,day);
Jan1 := EncodeDate(Year,1,1);
DaysElapsed := Trunc(DM1.TShipWtDATE.AsDateTime - Jan1) + 1;
JulianDate := format('%.3d',[DaysElapsed]);
end;


Simon Murrell wrote in message <36495619...@goaldata.co.za>...
>Hello
>
>Does anyone have a TDateTime converter to a Julian date format.
>
>Thanks
> Simon
>

James Lee Tabor

unread,
Nov 10, 1998, 3:00:00 AM11/10/98
to
Hi,

Here's a function converted from an NIST "C" language routine. It
returns the "modified Julian date". The C code is left in comments, any
error is translation is mine.

Jim

unit cvt2mjd;
//courtesy of -- time_a.timefreq.bldrdoc.gov
interface

function cvt2jd(yr, mo, day : LongInt) : LongInt;

implementation
//long int cvt2jd(yr,mo,day)
function cvt2jd(yr, mo, day : LongInt) : LongInt;
//int yr;
//int mo;
//int day;
//{
var
mjd, ilp : LongInt;
const
dom : array[1..12] of integer =
(0,31,59,90,120,151,181,212,243,273,304,334);
begin
//long int mjd; /*holds result*/
//int ilp; //number of leap years from 1900 not counting current
//static int dmo[12] = {0,31,59,90,120,151,181,212,243,273,304,334};
(*
this subroutine receives a date in the form year, month and day
and returns the MJD corresponding to that day. the year may
be specified as 90 or 1990.
*)
// if(yr > 1900) yr -= 1900; /* convert to years since 1900 */
if (yr > 1900) then
yr := yr - 1900;
// ilp=(yr-1)/4; /* number of leap years since 1900*/
ilp := (yr -1) div 4;
(*
compute number of days since 1900 + 1 day for each leap year
+ number of days since start of this year
*)
// mjd = 365*(long int) yr + (long int) (ilp + dmo[mo-1] + day - 1);
mjd := 365 * yr + (ilp + dom[mo-1] + day - 1);
// mjd += 15020; /* add MJD of 1900 */
mjd := mjd + 15020;
(*
if current month is jan or feb then it does not matter if
current year is a leap year
*)
// if(mo < 3) return(mjd);
if (mo < 3) then begin
Result := mjd;
exit;
end;
(*
if current month is march or later then must add 1 day if
current year is divisible by 4
*)
// if( (yr & 3) == 0) mjd++;
if ((yr and 3) = 0) then
inc(mjd);
Result := mjd;
// return(mjd);
//}
end;

end.

Simon Murrell

unread,
Nov 11, 1998, 3:00:00 AM11/11/98
to

Mike Bandor

unread,
Nov 11, 1998, 3:00:00 AM11/11/98
to
Simon Murrell <smur...@goaldata.co.za> wrote:

Simon,

In addition to the responses you have already received, on the
Delphi Super Page there is a JDATE component that gives Julian dates,
week numbers, etc. Best of all its FREE!

Mike
------------------------------------------------------
- Mike Bandor (ban...@vitrex.net)
- Software Engineer: Delphi/Ada/C++/Java/Win3.1/
- Win95/Winhelp/JOVIAL/MASM
-
- "Trying to manage programmers
- is like trying to herd cats!"
-
- Speaking for myself! Standard disclaimer applies.
------------------------------------------------------
- Author of MEGATERMS: Military Terms and Acronyms
- http://www.vitrex.net/~bandorm/megaterm/megaterm.htm
- ftp://vitrex.net/usr/b/bandorm/m-term.zip
------------------------------------------------------

Brandon Smith

unread,
Nov 11, 1998, 3:00:00 AM11/11/98
to
You need to say what kind of Julian date you want. Take a look at
Stockton's page at http://www.merlyn.demon.co.uk/index.htm for details on
some Pascal conversion routines and the code from my article from Issue 34
(june 98) of The Delphi Magazine at http://www.itecuk.com/delmag/index.htm.

Brandon C. Smith
B...@nospam.synature.com
http://www.synature.com

Dr John Stockton

unread,
Nov 11, 1998, 3:00:00 AM11/11/98
to
JRS: In article <3648AA89...@wtrt.net> of Tue, 10 Nov 1998
15:05:13 in news:borland.public.delphi.objectpascal, James Lee Tabor
<ku...@wtrt.net> wrote:

>Here's a function converted from an NIST "C" language routine. It
>returns the "modified Julian date". The C code is left in comments, any
>error is translation is mine.

You might like to compare it with that in my (BP7) dateprox.pas, tested
with mjd_date.pas, compiled together into mjd_date.exe, all to be found
in URL: http://www.merlyn.demon.co.uk/programs/ - in mine, DMY_to_MJD is
general, and DMYtoMJD is Gregorian.

Conversion to Delphi looks easy enough (undefine FASTER).

--
John Stockton, Surrey, UK. j...@merlyn.demon.co.uk Turnpike v4.00 MIME.
Web <URL: http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms & links.
PAS, EXE in <URL: http://www.merlyn.demon.co.uk/programs/> - see 00index.txt.
Do not Mail News to me. Before a reply, quote with ">" or "> " (SoRFC1036)

astr...@my-dejanews.com

unread,
Nov 13, 1998, 3:00:00 AM11/13/98
to

Might this have anything to do with the Platinum accounting product? If so, I
have a formula and can suggest a course of action. (please reply to
james....@mailexcite.com)

> Hello


>
> Does anyone have a TDateTime converter to a Julian date format.
>

> Thanks
> Simon
>
>


--

============================================
James Jensen

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/ Search, Read, Discuss, or Start Your Own

0 new messages