Adds units of time to a date.


A date/time object.


Date and time functions

Function syntax

DateAdd("datepart", number, "date")

See also

DateConvert, DatePart, CreateTimeSpan


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


Parameter Description



  • 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 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/time object, in the range 100 AD-9999 AD.


The datepart specifiers y, d, and w add a number of days to a date.

When passing a date/time object as a string, you must enclose it in quotation marks. Otherwise, it is interpreted as a numeric representation of a date/time object.


<!--- This example shows the use of DateAdd --->
<cfparam name="value" default="70">
<cfparam name="type" default="m">

<!--- if numbers passed, then use those --->
<cfif IsDefined("form.value")>
   <cfset value = form.value>
<cfif IsDefined("form.type")>
   <cfset type = form.type>

<cfquery name="GetMessages" datasource="cfdocexamples">
SELECT   UserName, Subject, Posted
FROM     Messages

<p>This example uses DateAdd to determine when a message in
the database will expire. Currently, messages older
than <cfoutput>#value#</cfoutput>

<cfswitch expression="#type#">
   <cfcase value="yyyy">years</cfcase>
   <cfcase value="q">quarters</cfcase>
   <cfcase value="m">months</cfcase>
   <cfcase value="y">days of year</cfcase>   
   <cfcase value="w">weekdays</cfcase>   
   <cfcase value="ww">weeks</cfcase>   
   <cfcase value="h">hours</cfcase>   
   <cfcase value="n">minutes</cfcase>   
   <cfcase value="s">seconds</cfcase>      
 are expired.

<cfoutput query="GetMessages">
   <td>#Posted# <cfif DateAdd(type, value, posted) LT Now()><font color="red">EXPIRED</font></cfif></td>

<cfform action="#CGI.Script_Name#" method="post">

Select an expiration value:
<cfinput type="Text" name="value" value="#value#" message="Please enter whole numbers only" validate="integer" required="Yes">
<select name="type">
   <option value="yyyy">years
   <option value="m" selected>months
   <option value="d">days
   <option value="ww">weeks            
   <option value="h">hours
   <option value="n">minutes
   <option value="s">seconds
<input type="Submit" value="Submit">

ColdFusion 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | KnowledgeBase | Bug Reporting

Version 7