CFLib.org – Common Function Library Project

GetSpanDate(dateObj , days, hours, minutes[, seconds])

Last updated December 12, 2001

author

Chris Wigginton

Version: 1 | Requires: CF5 | Library: DateLib

Description:
Returns a Date n days,hours,minutes, and seconds in the future or past by adding a timespan to the passed date.

Return Values:
Returns a date/time object.

Example:

<cfset Today = Now()>
<cfset EndDate = GetSpanDate(Today, 1,5,0,0)>
<cfoutput>
Today is #DateFormat(Today, "mm/dd/yyyy")# #TimeFormat(Today,"HH:mm:ss")#<p>
1 day and 5 hours later is: #DateFormat(EndDate, "mm/dd/yyyy")# #TimeFormat(EndDate,"HH:mm:ss")#<p>
</cfoutput>

Parameters:

Name Description Required
dateObj ColdFusion date object to use as the starting date. Yes
days Number of days in the timespan Yes
hours Number of hours in the timespan Yes
minutes Number of minutes in the timespan. Yes
seconds Number of seconds in the timespan. No

Full UDF Source:

/**
 * Adds a timespan to a date.

GetSpanDate(dateObj, days, hours, minutes, seconds)

Pass in a date object, with the span difference of days, hours, minutes, and seconds and returns a timestamp of the end of the span.
 * 
 * @param dateObj       ColdFusion date object to use as the starting date. 
 * @param days      Number of days in the timespan 
 * @param hours      Number of hours in the timespan 
 * @param minutes      Number of minutes in the timespan. 
 * @param seconds      Number of seconds in the timespan. 
 * @return Returns a date/time object. 
 * @author Chris Wigginton (cwigginton@macromedia.com) 
 * @version 1, December 12, 2001 
 */
function GetSpanDate(dateObj, days, hours, minutes, seconds){
  var timeDiff = CreateTimeSpan(days, hours, minutes, seconds);
  var spanDate = dateObj+timeDiff;
  return "{ts '" & DateFormat(spanDate, "yyyy-mm-dd ") & TimeFormat(spanDate, "HH:mm:ss") & "'}";
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson