CFLib.org – Common Function Library Project

LastDayOfMonth(strMonth[, strYear])

Last updated May 7, 2002

author

Ryan Kime

Version: 1 | Requires: CF5 | Library: DateLib

Description:
LastDayOfMonth() takes your selected month as a number (1-12) and an optional given year (which is good for instances of a Leap Year). It returns a date object that you can then use DateFormat to get the appropriate format for the month, day, and year.

Return Values:
Returns a date object.

Example:

<cfset month = 2>
<cfset year = 2004>

last day of the month is: 
<cfoutput>#LastDayOfMonth(month, year)#</cfoutput>
<br>- or -<br>
last day of the month is: 
<cfoutput>#DateFormat(LastDayOfMonth(month, year), "dddd mmm dd, yyyy")#</cfoutput>

Parameters:

Name Description Required
strMonth Month you want to get the last day for, Yes
strYear Year for the specified month. Useful for leap years. The default is the current year. No

Full UDF Source:

/**
 * Returns a date object representing the last day of the given month.
 * 
 * @param strMonth 	 Month you want to get the last day for, (Required)
 * @param strYear 	 Year for the specified month.  Useful for leap years.  The default is the current year. (Optional)
 * @return Returns a date object. 
 * @author Ryan Kime (ryan.kime@somnio.com) 
 * @version 1, May 7, 2002 
 */
function LastDayOfMonth(strMonth) {
  var strYear=Year(Now());
  if (ArrayLen(Arguments) gt 1)
    strYear=Arguments[2];
  return DateAdd("d", -1, DateAdd("m", 1, CreateDate(strYear, strMonth, 1)));
}
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