News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

An Added Benefit

Started by sukishan, Sep 04, 2009, 04:35 PM

Previous topic - Next topic

sukishan

An Added Benefit
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() + 1Date 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#
A good beginning makes a good ending