
Date within a Range of Dates
Quote:
>OK, this problem probably has a simple solution that's escaping me. I
>have 3 variables: AppointmentDate (type 7 variant), DaysBefore (integer)
>and DaysAfter (integer). I need to determine if a user-specified date
>falls within a date range specified by AppointmentDate-DaysBefore and
>AppointmentDate+DaysAfter.
>I assumed VB records its dates as a serial number, like Microsoft Works,
>but it looks like I'm wrong. Does anyone have a solution or suggestion
In ALL date related queries, I always convert the date to julian and work
from there. Just grab you a share snipit of code that converts a date to
a julian date and you'll be home free. I have
Pascal source, maybe even
basic source if you need it.
PsuedoCode:
DateToCheck$="01/01/94"
DaysBefore = 10
DaysAfter = 20
InPutDate$ = "02/02/95"
DateToCheckJulian = Date2Julian(DateToCheck$)
InputDateJulian = Date2Julian(InPutDate$)
If DateToCheckJulian - DaysBefore >= InputDateJulian and
DateToCheckJulian + DaysAfter <= InputDateJulian then
"InputDate$" is within the range.
I wrote this on the fly, and didn't really check my pluses and minuses
but in essence, you see how it works. Plus, julian dates NEVER lie.