Returns a Date containing a date to which a specified time interval has been added.
DateAdd(interval, number, date)
interval:sexp
number:iexp
date:any date exp
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 30 days from today.
The interval argument can have the following values:
"yyyy" | Year |
"q" | Quarter |
"m" | Month |
"y" | Day of year |
"d" | Day |
"w" | Weekday (1 = Sunday, … , 7 = Saturday) |
"ww" | Week |
The DateAdd function won't return an invalid date. The following example adds one month to January 31:
DateAdd("m", 1, "31-Jan-95")
In this case, DateAdd returns 28-Feb-95, not 31-Feb-95. If date is 31-Jan-96, it returns 29-Feb-96 because 1996 is a leap year.
If the calculated date would precede the year 100 (that is, you subtract more years than are in date), an error occurs.
Global x As Date, a%
x = DateAdd("ww", 4, Date) : Print x
// the actual date plus 4 weeks
x = DateAdd("yyyy", -9, Date) : Print x
// the year minus 9
x = DateAdd("m", -6, #12/31/1920#) : Print x
// the given date minus 6 month
// results 30/06/1920
You can indicate a time in hours, minutes and seconds, separated by “ : “; or only with four numbers for hours and minutes (with or without the using of AM or PM). Using only 4 characters forces the GFABASIC 32 editor to automatically add “:00“ for the seconds. When using AM or PM the editor automatically converts to 24 hour mode. For instance, "#2:24#" will automatically convert to #14:24:00#, and (#2:24AM#) => (#02:24:00#).
CDate(), Date, Date$, DateAdd(), DateDiff(), DatePart(), DateSerial(), DateTime$(), DateToDmy, DateToDmyHms, DateValue(), Day(), DayNo(), DmyHmsToDate(), DmyToDate(), HmsToTime(), Hour(), IsDate(), Minute(), Month(), Now, Now$(), TimeSerial(), TimeToHms, TimeValue(), Second(), Week(), WeekDay(), Year()
{Created by Sjouke Hamstra; Last updated: 28/09/2014 by James Gaite}