DateAdd Function

See AlsovbfctDateAddSee                 ExamplevbfctDateAddEx>Low

Description

Returns a Variant8PHEAW3 containing a date to which a specified time interval has been added.

Syntax

DateAdd( interval, number, date )

Remarks

The DateAdd function uses the following parts:

Part                 Description

 

interval             String expression1330R89 that is the interval of time you want to add.

number             Numeric expression71RISN that is the number of intervals you want to add.  It can be positive (to get dates in the future) or negative (to get dates in the past).

date                  Date being added to, or the name of a Variant containing a valid date.

 

You can use the DateAdd function to add or subtract a specified time interval from a date.  For example, you might use DateAdd to calculate a date 30 days from today or a time that is 45 minutes from now.

The following table lists the valid time periods and their interval values.  These intervals are also used by the Format function.

Time period     Interval

 

Year                 yyyy

Quarter             q

Month               m

Day of Year      y

Day                  d

Weekday          w

Week               ww

Hour                 h

Minute              n

Second             s

 

If you want to add days to date, you can use Day of Year, Day, or Weekday ("y," "d," or "w").

The DateAdd function won't return an invalid date.  The following example adds one month to January 31:

DateAdd("m", 1, "31-Jan-95")

 

In this case, DateAdd returns 28-Feb-95, not 31-Feb-95.  If date is 31-Jan-96, it returns 29-Feb-96 because 1996 is a leap year.

If the calculated date would precede the year 0 (that is, you subtract more years than are in date), an error occurs.

If number isn't a Long1DDU1E5 value, DateAdd follows the rules for the Fix function and rounds number to the nearest whole number.

 

Distribution Note   When you create and distribute applications that use this function in your code, you should install the file MSAFINX.DLL in the customer's Microsoft Windows \SYSTEM directory.  The Visual Basic Setup KitGUH5X7 provides tools to help you write setup programs that install your applications.