Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

' Convert a Gregorian Date to a Julian Day

' the function 'jd' adapted to vbscript from a jscript


' function by Dan Burton from a web page at
' http://www.isc.tamu.edu/~astro/javascript/julianday.html

'usage

'UTCNow = DateAdd("n", off, Now)
utcnow = Now()
y = Year(UTCNow)
m = Month(UTCNow)
d = Day(UTCNow)
h = Hour(UTCNow)
mn = Minute(UTCNow)
sec = Second(UTCNow)
wscript.echo jd(y, m, d, h, mn, sec)

'function usage: jd(YEAR, MONTH, DAY of MONTH, HOUR,
MINUTES, SECONDS)
Function jd(yy, mm, dd, hr, mn, sec)
'correct original which didn't properly handle BCE dates
if yy < 0 Then
yy = yy + 1
end If
hr = hr + (mn / 60) + sec/3600
ggg = 1
if yy <= 1585 then
ggg = 0
end If
jd = -1 * Int(7 * (Int((mm + 9) / 12) + yy) / 4)
s = 1
if (mm - 9) < 0 then
s = -1
end If
a = abs(mm - 9)
j1 = Int(yy + s * Int(a / 7))
j1 = -1 * Int((Int(j1 / 100) + 1) * 3 / 4)
jd = jd + Int(275 * mm / 9) + dd + (ggg * j1)
jd = jd + 1721027 + 2 * ggg + 367 * yy - 0.5
jd = round(jd + (hr / 24), 5)

end Function

You might also like