CFLib.org – Common Function Library Project

listFromDateRange(date1, date2[, thisDelimiter])

Last updated February 13, 2006
Download UDF

author

Christopher Jordan

Version: 1 | Requires: CF5 | Library: StrLib

Description:
ListFromDateRange can be given a starting and ending date and will return an inclusive list of dates between those two dates. The resulting list will be comma delimited unless a different delimiter is specifically specified as the optional third argument.

Return Values:
Returns a list.

Example:

<cfset thisDate_1 = now()>
<cfset thisDate_2 = dateAdd("d",5,thisDate_1)>
<cfoutput>Result from listFromDateRange: #listFromDateRange(thisDate_1,thisDate_2)#<br></cfoutput>
<cfloop index="i" list="#listFromDateRange(thisDate_1,thisDate_2)#">
	<cfoutput>Date This Itteration: #i#<br></cfoutput>
</cfloop>

Parameters:

Name Description Required
date1 First date to use. Yes
date2 Second date to use. Yes
thisDelimiter List delimiter to use for result. Defaults to a comma. No

Full UDF Source:

/**
 * ListFromDateRange returns a list of dates given a starting and ending date.
 * 
 * @param date1 	 First date to use. (Required)
 * @param date2 	 Second date to use. (Required)
 * @param thisDelimiter 	 List delimiter to use for result. Defaults to a comma. (Optional)
 * @return Returns a list. 
 * @author Christopher Jordan (cjordan@placs.net) 
 * @version 1, February 13, 2006 
 */
function listFromDateRange (date1,date2) {
	var i 				= 0;
	var numberOfDays	= 0;
	var thisDate	 	= "";
	var theList			= "";
	var temp			= "";
	var thisDelimiter	= ",";

	if(arraylen(arguments) eq 3) thisDelimiter = trim(arguments[3]);
	
	if (date1 GT date2) {
		temp	= date1;
		date1	= date2;
		date2	= temp;
	}

	numberOfDays = dateDiff("d",date1,date2);
	
	for(i = 0; i lte NumberOfDays; i = i + 1){
		thisDate = dateAdd("d",i,date1);
		theList = listAppend(theList,thisDate,thisDelimiter);
	}
	
	return theList;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Mosh Teitelbaum added
minutesToUtcOffs...
17 days ago

Mosh Teitelbaum added
utcOffsetToMinut...
17 days ago

Hank van Empel added
validateIBAN
18 days ago

CF Ninja added
calcIRR
2 months ago

Stephen Withington added
getWeekOfMonth
2 months ago

Created by Raymond Camden / Design by Justin Johnson