User Guide

436 Chapter 3: ColdFusion Functions
CreateTimeSpan
Description
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.
Returns
A date/time object.
Category
Date and time functions
Function syntax
CreateTimeSpan(days, hours, minutes, seconds)
See also
CreateDateTime, DateAdd, DateConvert
Parameters
Usage
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.
Example
<!--- 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. -------->
<cfoutput>
<cfquery name = "GetParks" datasource = "cfsnippets"
cachedWithin = "#CreateTimeSpan(0, 6, 0, 0)#">
SELECT PARKNAME, REGION, STATE
FROM Parks
ORDER by ParkName, State
</cfquery>
</cfoutput>
Parameter Description
days Integer in the range 0–32768; number of days in time period
hours Number of hours in time period
minutes Number of minutes in time period
seconds Number of seconds in time period