totn Excel Functions

MS Excel: How to use the DATEADD Function (VBA)

This Excel tutorial explains how to use the Excel DATEADD function with syntax and examples.

Description

The Microsoft Excel DATEADD function returns a date after which a certain time/date interval has been added.

The DATEADD function is a built-in function in Excel that is categorized as a Date/Time Function. It can be used as a VBA function (VBA) in Excel. As a VBA function, you can use this function in macro code that is entered through the Microsoft Visual Basic Editor.

Syntax

The syntax for the DATEADD function in Microsoft Excel is:

DateAdd ( interval, number, date )

Parameters or Arguments

interval

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
The number of intervals that you wish to add.
date
The date to which the interval should be added.

Returns

The DATEADD function returns a date value.

Applies To

  • Excel for Office 365, Excel 2019, Excel 2016, Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000

Type of Function

  • VBA function (VBA)

Example (as VBA Function)

The DATEADD function can only be used in VBA code in Microsoft Excel.

Let's look at some Excel DATEADD function examples and explore how to use the DATEADD function in Excel VBA code:

DateAdd("yyyy", 3, "22/11/2003")
Result: '22/11/2006'

DateAdd("q", 2, "22/11/2003")
Result: '22/05/2004'

DateAdd("m", 5, "22/11/2003")
Result: '22/04/2004'

DateAdd("n", 51, "22/11/2003 10:31:58 AM")
Result: '22/11/2003 11:22:58 AM'

DateAdd("yyyy", -1, "22/11/2003")
Result: '22/11/2002'

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'.