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. <P> 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());    
}
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