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; "Defining application-level settings and variables" in Chapter 13, "Designing and Optimizing a ColdFusion Application," in ColdFusion MX Developer's Guide
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 = "cfdocexamples"
       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, define startrow and maxrows. 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>#StartRow + MaxRows#
          </cfoutput>">See next <cfoutput>#MaxRows#</cfoutput> rows</A>
       </cfif>
       </TD>
    </TR>
    </TABLE>

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