CFLib.org – Common Function Library Project

CreateDateRange(startdate, ndays[, dtformat])

Last updated May 20, 2003

author

Casey Broich

Version: 1 | Requires: CF5 | Library: DateLib

Description:
Creates a date range array. The range starts with one date and goes N days into the future.

Return Values:
Returns an array.

Example:

<cfset arrDates = CreateDateRange(now(),10,"mmmm dd, yyyy")>

<cfdump var="#arrDates#">

Parameters:

Name Description Required
startdate The starting date. Yes
ndays The number of days. This will include the starting date. Yes
dtformat Date format. Defaults to "mm/dd/yyyy" No

Full UDF Source:

/**
 * Creates a date range array.
 * 
 * @param startdate 	 The starting date. (Required)
 * @param ndays 	 The number of days. This will include the starting date. (Required)
 * @param dtformat 	 Date format. Defaults to "mm/dd/yyyy" (Optional)
 * @return Returns an array. 
 * @author Casey Broich (cab@pagex.com) 
 * @version 1, May 20, 2003 
 */
function CreateDateRange(startdate,ndays) {
  var dtarray = arraynew(1);
  var i = 1;
  var ndate = "";
  var dtformat = "mm/dd/yyyy";
  
  if (ArrayLen(arguments) gte 3) dtformat = arguments[3];
  ndate = dateformat(startdate,"mm/dd/yyyy") - 1;
  for(i = 1; i lte ndays; i = i+1) {
    ndate = dateformat(ndate+1,dtformat);
    arrayappend(dtarray, ndate);
  }
  return dtarray;
}
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Kevin Cotton added
date2ExcelDate
May 5, 2016

Raymond Camden added
CapFirst
April 25, 2016

Chris Wigginton added
loremIpsum
January 18, 2016

Gary Stanton added
calculateArrival...
November 19, 2015

Sebastiaan Naafs - van Dijk added
getDaysInQuarter
November 13, 2015

Created by Raymond Camden / Design by Justin Johnson