<cffunction
name="GetNthDayOfMonth"
access="public"
returntype="any"
output="false"
hint="I return the Nth instance of the given day of the week for the given month (ex. 2nd Sunday of the month).">
<cfargument
name="Month"
type="date"
required="true"
hint="I am the month for which we are gathering date information."
/>
<cfargument
name="DayOfWeek"
type="numeric"
required="true"
hint="I am the day of the week (1-7) that we are locating."
/>
<cfargument
name="Nth"
type="numeric"
required="false"
default="1"
hint="I am the Nth instance of the given day of the week for the given month."
/>
<cfset var LOCAL = {} />
<cfset ARGUMENTS.Month = CreateDate(
Year( ARGUMENTS.Month ),
Month( ARGUMENTS.Month ),
1
) />
<cfif (DayOfWeek( ARGUMENTS.Month ) LTE ARGUMENTS.DayOfWeek)>
<cfset LOCAL.Date = (
ARGUMENTS.Month +
(ARGUMENTS.DayOfWeek - DayOfWeek( ARGUMENTS.Month ))
) />
<cfelse>
<cfset LOCAL.Date = (
ARGUMENTS.Month +
(7 - DayOfWeek( ARGUMENTS.Month )) +
ARGUMENTS.DayOfWeek
) />
</cfif>
<cfset LOCAL.Date += (7 * (ARGUMENTS.Nth - 1)) />
<cfreturn DateFormat( LOCAL.Date ) />
</cffunction>