CFLib.org – Common Function Library Project

LastMonth([Date])

Last updated September 6, 2001

author

Will Belden

Version: 1 | Requires: CF5 | Library: DateLib

Description:
Returns a date object representing the first day of the previous month. Optional parameters allows you to provide the date you want to calculate the prior month from.

Return Values:
Returns a date object.

Example:

<CFOUTPUT>
Last Month began on #DateFormat(LastMonth())#
</CFOUTPUT>

Parameters:

Name Description Required
Date Date object to go to the previous month on. Defaults to now. No

Full UDF Source:

/**
 * Returns a date object representing the first day of the previous month.
 * 
 * @param Date 	 Date object to go to the previous month on. Defaults to now. 
 * @return Returns a date object. 
 * @author Will Belden (wbelden@dwo.net) 
 * @version 1, September 6, 2001 
 */
function LastMonth() {
	var db = iif(arrayLen(arguments),"arguments[1]","now()");
	return DateAdd("m",-1,CreateDate(Year(db), Month(db), 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