– Common Function Library Project

listFromDateRange(date1, date2 [, thisDelimiter])

Last updated February 13, 2006

Version: 1 | Requires: ColdFusion 5 | Library: StrLib

Rated 0 time(s). Average Rating: 0

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.


view plain print about
<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>


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:

view plain print about
 * 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 ( 
 * @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


Latest Additions

CF Ninja CF Ninja added
a while ago

Stephen Withington Stephen Withington added
a while ago

Adam Cameron Adam Cameron added
a while ago

Ray Ford Ray Ford added
a while ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 49 time(s)

Barney Boisvert indentXml
Rated 5.0, 12 time(s)

Rachel Lehman deAccent
Rated 5.0, 9 time(s)

Darwan Leonardo Sitepu splitNumber
Rated 5.0, 9 time(s)

Created by Raymond Camden / Design by Justin Johnson