DATEADD(interval, number, date)

Returns the date with a specified time interval added (Date).


intervalThe interval of time you want to add (String):
"yyyy","YYYY" = year
"q","Q" = quarter
"m","M" = month
"y","Y" = day of year
"d","D" = day
"w","W" = weekday
"ww","WW" = week
"h","H" = hour
"n","N" = minute
"s","S" = second
numberThe number of intervals to add (Long).
dateThe date you want the interval added to (Date).

REMARKS
* The "number" can be any numeric expression.
* If "number" is not a Long, then it is rounded to the nearest whole number before getting evaluated.
* This function will never return an invalid date.
* If you subtract more time than is in the "date", then an error occurs.
* The format of the date that is returned is determined by the PC settings from the control panel.
* This function can be used to add or subtract a specified time interval from a date.
* You can use the DATEDIFF function to return the number of a given time interval between two specified dates.
* You can use the DATEPART function to return the specified part of a given date.
* The equivalent .NET function is Microsoft.VisualBasic.DateAndTime.DateAdd
* For the Microsoft documentation refer to docs.microsoft.com

Debug.Print DateAdd("m", 1, "31-Jan-95") = "31-Feb-95" 
Debug.Print DateAdd("m", 1, Now())
Debug.Print DateAdd("w", 2, Now())
Debug.Print DateAdd("h", 5, Now())
Debug.Print DateAdd("yyyy", 1, Now()) = 24/10/2009 16:53:02
Debug.Print DateAdd("yyyy", 1, "01-01-2008") = 01/01/2009
Debug.Print DateAdd("q", 1, "01-01-2008") = 01/04/2008
Debug.Print DateAdd("m", 1, "01-01-2008") = 01/02/2008
Debug.Print DateAdd("m", 1, "31-Jan-95") = 28/02/1995 'this adds one month
Debug.Print DateAdd("m", 1, Now()) = 24/11/2008 16:47:29
Debug.Print DateAdd("y", 1, "01-01-2008") = 02/01/2008
Debug.Print DateAdd("d", 1, "01-01-2008") = 02/01/2008
Debug.Print DateAdd("w", 1, "01-01-2008") = 02/01/2008
Debug.Print DateAdd("w", 5, "01-01-2008") = 06/01/2008
Debug.Print DateAdd("w", 2, Now()) = 26/10/2008 16:48:29
Debug.Print DateAdd("ww", 5, "01-01-2008") =5/02/2008
Debug.Print DateAdd("h", 5, Now()) = 24/10/2008 21:48:29
Debug.Print DateAdd("n", 5, Now()) = 24/10/2008 21:54:29
Debug.Print DateAdd("s", 10, Now()) = 24/10/2008 21:48:39
Debug.Print DateAdd("m", 1, CDate("31 Jan 2000") = '2000 is a leap year, do Feb has 28 days
Dim lserial As Long
lserial = DateAdd("d",1,"01/07/2012")

© 2019 Better Solutions Limited. All Rights Reserved. © 2019 Better Solutions Limited Top