CFLib.org – Common Function Library Project

LastMonth([Date])

Last updated September 06, 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));
}

Search CFLib.org


Latest Additions

Raymond Camden added
QueryDeleteRows
November 04, 2017

Leigh added
nullPad
May 11, 2016

Raymond Camden added
stripHTML
May 10, 2016

Kevin Cotton added
date2ExcelDate
May 05, 2016

Raymond Camden added
CapFirst
April 25, 2016

Created by Raymond Camden / Design by Justin Johnson