dateAdd

Adds units of time to a date.

dateAdd(datepart, number, date) → returns DateTime

Member Function Syntax

date.add(datepart, number)

dateAdd Argument Reference

datepart String
Required

yyyy - Year
q - Quarter
m - Month
y - Day of year
d - Day
w - Week day
ww - Week
h - Hour
n - Minute
s - Second
l - Millisecond
Values:
  • yyyy
  • q
  • m
  • y
  • d
  • w
  • ww
  • h
  • n
  • s
  • l

number Numeric
Required

The number of datepart units to add to the provided date.
Negative integers move the date into the past, positive into the future.

date Date
Required

Compatibility

ColdFusion:

Member function is available in CF11+.

Lucee:

Member function is available in Lucee4.5+

Examples sample code invoking the dateAdd function


Add Days to a Date

Add 30 days to August 3rd, 2014.

dateAdd('d', 30, '8/3/2014')

Expected Result: {ts '2014-09-02 00:00:00'}


Subtract Days from a Date

Subtract 30 days from August 3rd, 2014.

dateAdd('d', -30, '8/3/2014')

Expected Result: {ts '2014-07-04 00:00:00'}


Add Weeks to a Date

Here we're adding 8 weeks to the date August 3rd, 2014.

dateAdd('ww', 8, '8/3/2014')

Expected Result: {ts '2014-09-28 00:00:00'}


Fork me on GitHub