CFLib.org – Common Function Library Project

GetLastOccOfDayInMonth(TheDayOfWeek, TheMonth, TheYear)

Last updated August 22, 2001

Version: 1 | Requires: ColdFusion 5 | Library: DateLib

 
Rated 0 time(s). Average Rating: 0

Description:
Returns the day of the month(1-31) of Last Occurrence of a day (1-sunday,2-monday etc.) in a given month. Can be used to determine holidays or special events that occur on the last occurrence of a day in a month.

Return Values:
Returns a numeric value.

Example:

view plain print about
<CFOUTPUT>
The last Monday in May of 2001 is on May #GetLastOccOfDayInMonth(2,5,2001)#.
</CFOUTPUT>

Parameters:

Name Description Required
TheDayOfWeek Ordinal value representing the desired day of the week (1-sunday,2-monday etc.) Yes
TheMonth Ordinal value representing the month (1-January, 2-February, etc.) Yes
TheYear The year. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Returns the day of the month(1-31) of Last Occurrence of a day (1-sunday,2-monday etc.)
in a given month.
 * 
 * @param TheDayOfWeek      Ordinal value representing the desired day of the week (1-sunday,2-monday etc.) 
 * @param TheMonth      Ordinal value representing the month (1-January, 2-February, etc.) 
 * @param TheYear      The year. 
 * @return Returns a numeric value. 
 * @author Ken McCafferty (mccjdk@yahoo.com) 
 * @version 1.0, August 22, 2001 
 */

function GetLastOccOfDayInMonth(TheDayOfWeek,TheMonth,TheYear) 
{
  //Find The Number of Days in Month
  Var TheDaysInMonth=DaysInMonth(CreateDate(TheYear,TheMonth,1));
  //find the day of week of Last Day
  Var DayOfWeekOfLastDay=DayOfWeek(CreateDate(TheYear,TheMonth,TheDaysInMonth));
  //subtract DayOfWeek
  Var DaysDifference=DayOfWeekOfLastDay - TheDayOfWeek;
  //Add a week if it is negative
  if(DaysDifference lt 0){
    DaysDifference=DaysDifference + 7;
  }
  return TheDaysInMonth-DaysDifference;
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Tayo Akinmade Tayo Akinmade added
arrayTrim
3 day(s) ago

Will Belden Will Belden added
longTime
9 day(s) ago

James Sleeman James Sleeman added
quickSort
19 day(s) ago

Ben Forta Ben Forta added
GetHostAddress
22 day(s) ago

Top Rated

Darwan Leonardo Sitepu EksporSQLData
Rated 5.0, 16 time(s)

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 13 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson