DateAdd Function
Returns a date to which a specified time interval has been added.
Syntax
DateAdd(interval, number, date)
Arguments:
- Interval: Required. String expression that is the interval you want to add. See Settings section for values.
- Number: Required. Numeric expression that is the number of intervals you want to add. The numeric expression can either be positive, for dates in the future, or negative, for dates in the past.
- Date: Required. Variant or literal representing the date to which interval is added.
Settings: The interval argument can have the following values:
Table 11-9 Interval Argument Values
Setting | Description |
---|---|
yyyy | Year |
q | Quarter |
m | Month |
d | Day |
w | Weekday |
h | Hour |
n | Minute |
s | Second |
Supported Date Formats:
MM/DD/YYYY
DD/MM/YYYY
YYYY-MM-DD
YYYY/MM/DD
Supported Time Format:
hh:mm:ss
Remarks
You can use the DateAdd
function to add or subtract a specified time
interval from a date. For example, you can use DateAdd
to calculate
a date 10 days from today or a time 45 minutes from now. To add days to date, you
can use Day ("d"), or Weekday ("w").
Output date format is based on the system’s short date format.
The following example illustrates the use of the DateAdd
function:
Example 1:
Dim MyDate, NewDate
MyDate = "21/01/2025"
NewDate = DateAdd("yyyy", 5, MyDate)
'Output: 21-Jan-30
Example 2:
Dim MyDate, NewDate
MyDate = "21/01/2025"
NewDate = DateAdd("q", 1, MyDate)
'Output: 21-Apr-25
Example 3:
Dim MyDate, NewDate
MyDate = "21/01/2025"
NewDate = DateAdd("m", 2, MyDate)
'Output: 21-Mar-25
Example 4:
Dim MyDate, NewDate
MyDate = "21/01/2025"
NewDate = DateAdd("d", 10, MyDate)
'Output: 31-Jan-25
Example 5:
Dim MyDate, NewDate
MyDate = "21/01/2025"
NewDate = DateAdd("w", 4, MyDate)
'Output: 25-Jan-25
Example 6:
Dim MyDate, NewDate
MyDate = "21/01/2025 14:40:00"
NewDate = DateAdd("h", 5, MyDate)
'Output: 21-Jan-25 7:40:00 PM
Example 7:
Dim MyDate, NewDate
MyDate = "21/01/2025 14:40:00"
NewDate = DateAdd("n", 5, MyDate)
'Output: 21-Jan-25 2:45:00 PM
Example 8:
Dim MyDate, NewDate
MyDate = "21/01/2025 14:40:00"
NewDate = DateAdd("s", 5, MyDate)
'Output: 21-Jan-25 2:40:05 PM