Creates a date/time object that defines a time period. You can add or subtract it from other date-time objects and use it with the cachedWithin attribute of cfquery.


A date-time object. (A Java Double)


Date and time functions

Function syntax

CreateTimeSpan(days, hours, minutes, seconds)

See also

CreateDateTimeDateAddDateConvertDefining application-level settings and variables in Defining the application and its event handlers in Application.cfc in the Developing ColdFusion Applications





Integer in the range 0-32768; number of days in time period


Number of hours in time period


Number of minutes in time period


Number of seconds in time period


Creates a special date-time object that should be used only to add and subtract from other date-time objects or with the cfquery cachedWithin attribute.If you use the cachedWithin attribute of cfquery, and the original query date falls within the time span you define, cached query data is used. In this case, the CreateTimeSpan function is used to define a period of time from the present backwards. The cachedWithin attribute takes effect only if you enable query caching in the ColdFusion Administrator. For more information, see cfquery.


<!--- This example shows the use of CreateTimeSpan with cfquery ---> 
<h3>CreateTimeSpan Example</h3> 
<!--- define startrow and maxrows to facilitate 'next N' style browsing ---> 
<CFPARAM name = "MaxRows" default = "10"> 
<CFPARAM name = "StartRow" default = "1"> 
<!--- Query database for information, if cached database information has not been updated in the last six hours. --------> 
<cfquery name = "GetParks" datasource = "cfdocexamples" 
cachedWithin = "#CreateTimeSpan(0, 6, 0, 0)#"> 
FROM Parks 
ORDER by ParkName, State 
<!--- build HTML table to display query ---> 
<TABLE cellpadding = 1 cellspacing = 1> 
<TD colspan = 2 bgcolor = f0f0f0> 
<B><I>Park Name</I></B> 
<TD bgcolor = f0f0f0> 
<TD bgcolor = f0f0f0> 
<!--- Output query, define startrow and maxrows. Use query variable CurrentCount to track the row you are displaying. ---> 
<cfoutput query = "GetParks" StartRow = "#StartRow#" 
MAXROWS = "#MaxRows#"> 
<TD valign = top bgcolor = ffffed> 
<TD valign = top> 
<FONT SIZE = "-1">#ParkName#</FONT> 
<TD valign = top> 
<FONT SIZE = "-1">#Region#</FONT> 
<TD valign = top> 
<FONT SIZE = "-1">#State#</FONT> 
<!--- If number of records is less than or equal to number of rows, offer link to same page, with startrow value incremented by maxrows (in this example, 
incremented by 10). ---> 
<TD colspan = 4> 
<cfif (StartRow + MaxRows) LTE GetParks.RecordCount> 
<a href = "cfquery.cfm?startrow = <cfoutput>#StartRow + MaxRows# 
</cfoutput>">See next <cfoutput>#MaxRows#</cfoutput> rows</A> 

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