CFLib.org – Common Function Library Project

NextOccOfDOW([day])

Last updated August 22, 2001

author

Rob Brooks-Bilson

Version: 1 | Requires: CF5 | Library: DateLib

Description:
Returns a date object representing the next occurrence of the specified day. The default is the next occurrence of the current day.

This function is based on an idea submitted by Larry Juncker (ljuncker@aljcompserv.com).

Return Values:
Returns a date.

Example:

<CFOUTPUT>
<CFLOOP INDEX="i" FROM="1" TO="7">
The next occurrence of #DayOfWeekAsString(i)# is #DateFormat(NextOccOfDOW(i), 'mmmm dd, yyyy')#.<BR>
</CFLOOP>
</CFOUTPUT>

Parameters:

Name Description Required
day Ordinal day of the week. 1=Sunday, 2=Monday, 3=Tuesday, etc. No

Full UDF Source:

/**
 * Returns a date object representing the next occurrence of the specified day.  The default is the next occurrence of the current day.
 * This function is based on an idea submitted by Larry Juncker (ljuncker@aljcompserv.com).
 * 
 * @param day      Ordinal day of the week.  1=Sunday, 2=Monday, 3=Tuesday, etc.   
 * @return Returns a date. 
 * @author Rob Brooks-Bilson (rbils@amkor.com) 
 * @version 1, August 22, 2001 
 */
function  NextOccOfDOW()
{
  Var day = DayOfWeek(Now());
  Var dayOffset = 7;
  if(ArrayLen(Arguments)) 
    day = Arguments[1];
  if(Day GT DayOfWeek(Now()))
    dayOffset = 0;
  return DateAdd("d",(dayOffset + (day - DayOfWeek(Now()))),Now());    
}

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