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

Quick Reply

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it has been approved by a moderator.

Name:
Email:
Verification:
Please leave this box empty:
Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:

Shortcuts: ALT+S post or ALT+P preview