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 Now() = 21/07/2020 21:42:06 
Debug.Print DateAdd("yyyy", 1, Now()) = 21/07/2021 21:42:06
Debug.Print DateAdd("yyyy", 1, "01-01-2020") = 01/01/2020
Debug.Print DateAdd("q", 1, "01-01-2020") = 01/04/2020
Debug.Print DateAdd("m", 1, Now()) = 21/08/2020 21:42:06
Debug.Print DateAdd("m", 1, "01-01-2020") = 01/02/2020

'2020 is a leap year, so February has 29 days
Debug.Print DateAdd("m", 1, CDate("31 Jan 2000")) = 29/02/2020

Debug.Print DateAdd("y", 1, "01-01-2020") = 02/01/2020
Debug.Print DateAdd("d", 1, "01-01-2020") = 02/01/2020
Debug.Print DateAdd("w", 1, "01-01-2020") = 02/01/2020
Debug.Print DateAdd("w", 5, "01-01-2020") = 06/01/2020
Debug.Print DateAdd("w", 2, Now()) = 23/07/2020 21:42:06
Debug.Print DateAdd("w", 2, Now()) = 23/07/2020 21:42:06
Debug.Print DateAdd("ww", 5, "01-01-2020") = 5/02/2020

Debug.Print DateAdd("h", 5, Now()) = 22/07/2020 02:29:06
Debug.Print DateAdd("h", 5, Now()) = 22/07/2020 02:42:06
Debug.Print DateAdd("n", 5, Now()) = 21/07/2020 21:47:06
Debug.Print DateAdd("s", 10, Now()) = 21/07/2020 21:42:16

Dim lSerial As Long
lSerial = DateAdd("d",1,"01/07/2012")
Debug.Print lSerial = 41092

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