CFLib.org – Common Function Library Project

isUsefulDate(date)

Last updated July 25, 2012

author

Alan McCollough

Version: 1 | Requires: CF5 | Library: DateLib

Description:
isUsefulDate() tests for valid dates, but also tests that the date is within a century of now. Why? Dates outside that range are probably fat-fingered so you have a year of "201" or "20100" instead of "2010". Unless you are a historian or a futurist, you probably don't use dates beyond a hundred years of now; but if you do, feel free to increase the 100-year test in the UDF.

Return Values:
Returns a boolean

Example:

isUsefulDate("blah")=false
isUsefulDate("9/14/201")=false
isUsefulDate("9/14/2010")=true
isUsefulDate("9/14/20100")=false

Parameters:

Name Description Required
date The value to test Yes

Full UDF Source:

/**
 * Tests if a date is valid, and within a century of today.
 * version 1.0 by Alan McCollough
 * 
 * @param date 	 The value to test (Required)
 * @return Returns a boolean 
 * @author Alan McCollough (amccollough@anthc.org) 
 * @version 1, July 25, 2012 
 */
function isUsefulDate(date){
	if(isDate(date)){
		if(abs(dateDiff("yyyy",date,now())) LTE 100)
			return true;
		else
			return false;
		}
	else
		return false;
}
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