Code archives/Miscellaneous/Julian Days conversion

This code has been declared by its author to be Public Domain code.

Download source code

Julian Days conversion by Imphenzia
(Posted 24 years ago)
This is a simple method of converting Blitz dates into "Julian Days". Using this format you can convert any two dates into Julian Days and then simply substract the two resulting numbers to get the number of days between those dates without having to worry about days per month, leap years and all the rest! Can for example be used for calculating trial periods.
Dim Months$(12)
Months(1)="JAN":Months(2)="FEB":Months(3)="MAR":Months(4)="APR":Months(5)="MAY":Months(6)="JUN": Months(7)="JUL": Months(8)="AUG": Months(9)="SEP": Months(10)="OCT": Months(11)="NOV": Months(12)="DEC"

Print "Days between today and 23 Aug 2008: " + (JulianDays("23 AUG 2008") - JulianDays(CurrentDate()))

Function FindMonth(fm$)
  For i=1 To 12
  If Upper(fm$)=months$(i) Then Return i
  Next
End Function

Function JulianDays(txt$)
  d=Int(Left(txt$,2))
  m=Int(FindMonth(Mid(txt$,4,3)))
  y=Int(Right(txt$,4))
  jd=( 1461 * ( y + 4800 + ( m - 14 ) / 12 ) ) / 4 + ( 367 * ( m - 2 - 12 * ( ( m - 14 ) / 12 ) ) ) / 12 - ( 3 * ( ( y + 4900 + ( m - 14 ) / 12 ) / 100 ) ) / 4 + d - 32075
  Return jd
End Function