DateAdd

Adds units of time to a date object.

Returns: datetime

Usage

DateAdd( datepart, number, date )

Arguments

Argument Description
datepart
(string, required)

One of the following units:

  • yyyy: Year
  • q: Quarter
  • m: Month
  • y: Day of year
  • d: Day
  • w: Weekday
  • ww: Week
  • h: Hour
  • n: Minute
  • s: Second
  • l: Millisecond
number
(number, required)

Number of units of datepart to add to date (positive, to get dates in the future; negative, to get dates in the past). Number must be an integer.

date
(datetime, required)

date object; for example, now()

Examples

// the below code increments 10 milliseconds in actual date
  dump(dateAdd("l", 10, now()));

  // the below code increments 60 seconds in actual date
  dump(dateAdd("s", 60, now()));

  // the below code increments 60 minutes in actual date
  dump(dateAdd("n", 60, now()));

  // the below code increments 2 hours in actual date
  dump(dateAdd("h", 2, now()));

  // the below code increments 1 day in actual date
  dump(dateAdd("d", 1, now()));

  // the below code increments 1 month in actual date
  dump(dateAdd("m", 1, now()));

  // the below code increments 1 year in actual date
  dump(dateAdd("yyyy", 1, now()));

See also