How To Find Number of Days Between Dates Outside of Normal Range (109451)
The information in this article applies to:
- Microsoft Visual Basic Standard Edition for Windows 3.0
- Microsoft Visual Basic Professional Edition for Windows 3.0
This article was previously published under Q109451 SUMMARY
To find the number of days between any two dates, you can take the
difference between the values returned by the DateSerial function for two
dates. However, the DateSerial function only supports dates from January 1,
100 through December 31, 9999.
To support a much wider range of dates, use the AstroDay function as in
this example:
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 Function
For 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 2
In 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.
Modification Type: | Minor | Last Reviewed: | 7/1/2004 |
---|
Keywords: | kbhowto KB109451 |
---|
|