How to Find Num of Days Between Dates Outside of Normal RangeLast reviewed: March 20, 1998Article ID: Q109451 |
3.00
WINDOWS
kbprg kbcode
The information in this article applies to: - Standard and Professional Editions of Microsoft Visual Basic for Windows, version 3.0
SUMMARYTo 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 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.
MORE INFORMATIONThe AstroDay function defined in this article is a modified version of the Julian date formula used by astronomers. Visual Basic's DateSerial function returns a Variant of VarType 7 (Date) containing a date that is stored internally as a double-precision number. This number represents a date from January 1, 100 through December 31, 9999, where January 1, 1900 is 2. Negative numbers represent dates prior to December 30, 1899. Leap years are accurately handled by both Visual Basic's DateSerial function and the Astronomical Day function (AstroDay) defined in this article. A leap year is defined as all years divisible by 4, except for years divisible by 100 that are not also divisible by 400. Years divisible by 400 are leap years. 2000 is a leap year. 1900 is not a leap year.
Step-by-Step Example
|
Additional reference words: 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |