CFLib.org – Common Function Library Project

decade(year)

Last updated July 27, 2012

author

Mosh Teitelbaum

Version: 1 | Requires: CF6 | Library: DateLib

Description:
Returns the decade (xxx0-xxx9) to which the specified year belongs.

Return Values:
Returns a string

Example:

#decade("1983")# = 1980-1989<br />
#listFirst(decade("1983"), "-")# = 1980<br />
#listLast(decade("1983"), "-")# = 1989<br />

Parameters:

Name Description Required
year Year to use Yes

Full UDF Source:

<!---
 Returns the decade (xxx0-xxx9) to which the specified year belongs.
 
 @param year      Year to use (Required)
 @return Returns a string 
 @author Mosh Teitelbaum (mosh.teitelbaum@evoch.com) 
 @version 1, July 27, 2012 
--->
<cffunction name="decade" returntype="string" output="no">
    <cfargument name="year" type="numeric" required="yes">

    <cfset var startYear = arguments.year - (arguments.year MOD 10)>
    <cfset var endYear = arguments.year + (10 - (arguments.year MOD 10) - 1)>

    <cfreturn startYear & "-" & endYear>
</cffunction>

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