Thanks to Nelson Zink and David Jones for their code snippets for converting
Julian dates.
Below are two functions derived from Nelson Zink's code to go from standard
date format to Julian and back again. I've modified the code into
functions, changed the variable names to minimize potential name space
conflicts, and added local declarations so they'll work with or without
explicitvars on:
--
-- Date2Julian
--
-- Accepts any valid date format and returns a
-- Julian date value.
-- Derived from original code by Nelson Zink.
--
function Date2Julian pDate
local tYear, tMonth, tDay, aa, bb, cc, dd
convert pDate to dateitems
put item 1 of pDate into tYear
put item 2 of pDate into tMonth
put item 3 of pDate into tDay
if tMonth<=2 then
add 12 to tMonth
subtract 1 from tYear
end if
put trunc(tYear/100) into aa
put (2-aa+trunc(aa/4)) into bb
put trunc(365.25*tYear) into cc
put trunc(30.6001*(tMonth+1)) into dd
return (bb+cc+dd+tDay+1720995)
end Date2Julian
--
-- Julian2Date
--
-- Accepts a Julian number and returns a Gregorian
-- date in the format MM/DD/YYYY.
-- Derived from original code by Nelson Zink.
--
function Julian2Date pJulianDate
local tYear, tDay, tMonth, aa, bb, cc, dd, ee, gg
put trunc((pJulianDate-1867216.25)/36524.25) into aa
put pJulianDate+1+aa-trunc(aa/4) into bb
Put bb+1524 into cc
put trunc((cc-122.1)/365.25) into dd
put trunc(365.25*dd) into ee
put trunc((cc-ee)/30.6001) into gg
put cc-ee-trunc(30.6001*gg) into tDay
if gg<13.5 then put gg-1 into tMonth else put gg-13 into tMonth
if tMonth>2.5 then put dd-4716 into tYear else put dd-4715 into tYear
return tMonth&"/"&tDay&"/"&tYear
end Julian2Date
--
Richard Gaskin
Fourth World Media Corporation
Multimedia Design and Development for Mac, Windows, UNIX, and the Web
_____________________________________________________________________
[EMAIL PROTECTED] http://www.FourthWorld.com
Tel: 323-225-3717 AIM: FourthWorldInc Fax: 323-225-0716
Archives: http://www.mail-archive.com/[email protected]/
Info: http://www.xworlds.com/metacard/mailinglist.htm
Please send bug reports to <[EMAIL PROTECTED]>, not this list.