Because VBA stores dates internally as serial values, you get the added benefit of being able to treat dates as numeric values in expressions if you want. Although VBA supplies the DateAdd function, covered in more detail in the section “Performing Simple Calculations” later in this chapter, you needn’t use it if you’re adding a number of days to a given date value. For example, to get tomorrow’s date, you could just add 1 to today’s date, like this:
dtmTomorrow = Date() + 1
Date is a built-in VBA function that returns the date portion (the integer part) of the current date and time retrieved from Windows. Adding 1 to that value returns a date that represents the next day.
The same mechanism works for subtracting two dates. Although VBA supplies the DateDiff function for finding the interval spanned by two date/time values, if you just need to know the number of days between the two dates, you can simply subtract one from the other. For example, to find the number of days between 5/22/97 and 1/10/97, you could use an expression like this:
intDays = #5/22/97# - #1/10/97#
Afterward, intDays will contain the value 132, the number of days between May 22 and January 10.