User Guide Cancel

DateAdd

 

Description

Adds units of time to a date.

Returns

A date/time object.

Category

Date and time functions

Function syntax

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

Output

{ts '2433-09-01 23:59:59'}{ts '2433-09-02 00:00:29'}

Get help faster and easier

New user?