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.
CreateTimeSpan(days, hours, minutes, seconds)
CreateDateTime, DateAdd, DateConvert
The CreateTimeSpan function 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, cached query data is used if the original query date falls within the time span you define. In this case, the CreateTimeSpan function is used to define a period of time from the present backwards. The cachedWithin attribute is effective only if you enable query caching in the ColdFusion Administrator. See cfquery for more details.
<!--- This example shows the use of CreateTimeSpan with cfquery --->
<html>
<head>
<title>CreateTimeSpan Example</title>
</head>
<body bgcolor = "#FFFFD4">
<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>
<!--- build HTML table to display query --->
<TABLE cellpadding = 1 cellspacing = 1>
<TR>
<TD colspan = 2 bgcolor = f0f0f0>
<B><I>Park Name</I></B>
</TD>
<TD bgcolor = f0f0f0>
<B><I>Region</I></B>
</TD>
<TD bgcolor = f0f0f0>
<B><I>State</I></B>
</TD>
</TR>
<!--- Output query and define startrow and maxrows
parameters. Use query variable CurrentCount to track
the row you are displaying. --->
<cfoutput query = "GetParks" StartRow = "#StartRow#"
MAXROWS = "#MaxRows#">
<TR>
<TD valign = top bgcolor = ffffed>
<B>#GetParks.CurrentRow#</B>
</TD>
<TD valign = top>
<FONT SIZE = "-1">#ParkName#</FONT>
</TD>
<TD valign = top>
<FONT SIZE = "-1">#Region#</FONT>
</TD>
<TD valign = top>
<FONT SIZE = "-1">#State#</FONT>
</TD>
</TR>
</cfoutput>
<!--- 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) --->
<TR>
<TD colspan = 4>
<cfif (StartRow + MaxRows) LTE GetParks.RecordCount>
<a href = "cfquery.cfm?startrow = <cfoutput>
#Evaluate(StartRow + MaxRows)#</cfoutput>">
See next <cfoutput>#MaxRows#</cfoutput> rows</A>
</cfif>
</TD>
</TR>
</TABLE>
</body>
</html>