Excel: DateAdd Function (VBA only)
In Excel, the DateAdd function returns a date after which a certain time/date interval has been added.
The syntax for the DateAdd function is:
DateAdd ( interval, number, date )
interval is the time/date interval that you wish to add. It can be one of the following values:
Value Explanation yyyy Year q Quarter m Month y Day of the year d Day w Weekday ww Week h Hour n Minute s Second
number is the number of intervals that you wish to add.
date is the date to which the interval should be added.
Applies To:
- Excel 2007, Excel 2003, Excel XP, Excel 2000
For example:
DateAdd("yyyy", 3, "22/11/2003") would return '22/11/2006' DateAdd("q", 2, "22/11/2003") would return '22/05/2004' DateAdd("m", 5, "22/11/2003") would return '22/04/2004' DateAdd("n", 51, "22/11/2003 10:31:58 AM") would return '22/11/2003 11:22:58 AM' DateAdd("yyyy", -1, "22/11/2003") would return '22/11/2002'
VBA Code
The DateAdd function can only be used in VBA code. For example:
Dim LDate As Date
LDate = DateAdd("s", 53, "22/11/2003 10:31:58 AM")
In this example, the variable called LDate would now contain the value of '22/11/2003 10:32:51 AM'.