createTimespan

Returns a value that defines a time period, represented by a numeric (double) where 1 equals 1 day. 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) → returns numeric

Argument Reference

days numeric
Required

The number of days ranging from 0 to 32768

hours numeric
Required

The number of hours

minutes numeric
Required

The number of minutes

seconds numeric
Required

The number of seconds

Examples
Sample code invoking the createTimespan function

The createTimespan function is useful in the cachedwithin attribute of cfquery.

<cfquery name = "GetParks" datasource = "cfdocexamples" cachedWithin = "#createTimespan(0, 6, 0, 0)#"> 
 SELECT PARKNAME, REGION, STATE 
 FROM Parks 
 ORDER by ParkName, State 
 </cfquery>

Passing 6 hours, or a quarter of a day returns a double representing 1/4

createTimespan(0, 6, 0, 0)

Expected Result: 0.25

Instead of using dateAdd you could add a timestamp to a date object

dateFormat( createDate(2017,1,1) + createTimespan(2,0,0,0) )

Expected Result: 03-Jan-17

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub