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;
}

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