Description

Adds units of time to a date.

Returns

A date/time object.

Category

Date and time functions

Function syntax

DateAdd(datepart, number, date)

See also

DateConvertDatePartCreateTimeSpan

History

ColdFusion MX 6.1: Added the datepart character L or l to represent milliseconds.

Parameters

Parameter

Description

datepart

String:

  • 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 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

Date/time object, in the range 100 AD-9999 AD.

Usage

The datepart specifiers y, d, and w add a number of days to a date.When passing a date/time object as a string, enclose it in quotation marks. Otherwise, it is interpreted as a numeric representation of a date/time object.

Example

<cfscript>
    date="{ts '2433-09-01 23:59:59'}";
	writeOutput("#date#");
    diff=30;
    posdateresult=DateAdd("s",diff,date);
	writeOutput("#posdateresult#");
</cfscript>

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy