Article ID: 109451
Article Last Modified on 7/1/2004
Function AstroDay(inyear, inmonth, inday) ' The AstroDay function returns the Astronomical Day for any given date. y = inyear + (inmonth - 2.85) / 12 AstroDay=Int(Int(Int(367*y)-1.75*Int(y)+inday)-.75*Int(.01*y))+1721119 ' NOTE: Basic's Int function returns the integer part of a number. End FunctionFor example, the number of days between February 28, 12000 and March 1, 12000 is 2 because the year 12000 is a leap year:
Print AstroDay(12000, 3, 1) - AstroDay(12000, 2, 28) 'Prints 2In addition, the AstroWeekDay function defined farther below returns the day of the week, Sunday through Monday, for any given AstroDay. AstroWeekDay supports dates outside the range (January 1, 100 through December 31, 9999) of Visual Basic's WeekDay function.
Sub Form_Load ()
form1.Show ' Must first Show form in Load event for Print to work.
Print AstroDay(12000, 3, 1) - AstroDay(12000, 2, 28) 'Prints 2
Print AstroDay(-12400, 3, 1) - AstroDay(-12400, 2, 28) 'Prints 2
Print AstroDay(12000, 3, 1) - AstroDay(-12000, 2, 28) 'Prints 8765822
Print AstroDay(1902, 2, 28) - AstroDay(1898, 3, 1) 'Prints 1459 days
Print AstroWeekDay(AstroDay(1993, 12, 1)) ' Prints Wednesday
Print AstroWeekDay(AstroDay(12000, 3, 2)) ' Prints Thursday
' You can also use Visual Basic's DateSerial function as follows to
' find the number of days between two dates:
Print DateSerial(1902, 2, 28) - DateSerial(1898, 3, 1)
' Visual Basic's WeekDay function returns an integer betw 1 (Sunday)
' and 7 (Saturday), which represents the day of the week for a date
' argument:
Print "Day of week = " & Weekday(DateSerial(1898, 3, 1))
End Sub
Function AstroDay(inyear, inmonth, inday)
' The AstroDay function returns the Astronomical Day for any given date.
y = inyear + (inmonth - 2.85) / 12
AstroDay=Int(Int(Int(367*y)-1.75*Int(y)+inday)-.75*Int(.01*y))+1721119
' NOTE: Basic's Int function returns the integer part of an number.
End Function
Function AstroWeekDay (aday)
' The AstroWeekDay function returns the day of the week, Sunday through
' Monday, for any given AstroDay. The aday parameter must be a day
' number returned by the AstroDay function.
weekdayx = (aday - 3) Mod 7
Select Case weekdayx
Case 0
AstroWeekDay = "Sunday"
Case 1
AstroWeekDay = "Monday"
Case 2
AstroWeekDay = "Tuesday"
Case 3
AstroWeekDay = "Wednesday"
Case 4
AstroWeekDay = "Thursday"
Case 5
AstroWeekDay = "Friday"
Case 6
AstroWeekDay = "Saturday"
End Select
End Function
Keywords: kbhowto KB109451