6.1.2.4.1.1 DateAdd

Function Declaration

 Function DateAdd(Interval As String,  
                  Number As Double,  
                  Date As Variant)  

Parameter

Description

Interval

String data value (section 2.1) that specifies the interval of time to add.

Number

The number of intervals to add. It can be positive (to get dates in the future) or negative (to get dates in the past). If it is not a integer value, it is rounded to the nearest whole number.

Date

Date, data value to which the interval is added.

Runtime Semantics.

  • The DateAdd function returns the result of adding or subtracting a specified time interval from a base date. For example, it can be used to calculate a date 30 days from today or a time 45 minutes from now.

  • The interval argument is interpreted according to this table:

    Interval Data Value

    Meaning

    "yyyy"

    Year

    "q"

    Quarter

    "m"

    Month

    "y"

    Day of year

    "d"

    Day

    "w"

    Weekday

    "ww"

    Week

    "h"

    Hour

    "n"

    Minute

    "s"

    Second

    Any other data value

    Raise Error 5, "Invalid procedure call or argument"

     

  • The interpretation of the Interval data value is not case sensitive.

  • 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-Feb96 because 1996 is a leap year.

  • If the calculated date would precede the year 100 (that is, you subtract more years than are in date), an error 5 is raised.

  • For date, if the Calendar property setting is Gregorian, the supplied date MUST be Gregorian. If the calendar is Hijri, the supplied date MUST be Hijri. If month values are names, the name MUST be consistent with the current Calendar property setting. To minimize the possibility of month names conflicting with the current Calendar property setting, enter numeric month values (Short Date format).