CFLib.org – Common Function Library Project

datePatternMatch(dateString, datePattern)

Last updated July 25, 2013

author

Matt Graff

Version: 1 | Requires: CF9 | Library: DateLib

Description:
For a data import from a spreadsheet I needed a way to determine if a string was in the format dd-MMM-yy so I knew to transform it to another database friendly format (ie mm/dd/yyyy)

Return Values:
A boolean indicating whether the datestring is in the format specified by datepattern

Example:

<cfset setLocale("French (Standard)")>
<cfoutput>
	#datePatternMatch("25 juillet 2013", "d mmmm yyyy")#<br><!---true --->
	#datePatternMatch("25 july 2013", "d mmmm yyyy")#<br><!--- false because "july" is not valid in French --->
</cfoutput>

Parameters:

Name Description Required
dateString A string containing a date in the current locale Yes
datePattern A string containing a date format mask (as per LSDateFormat()) Yes

Full UDF Source:

/**
 * Determine if a date string is in a particular pattern
 * v0.9 by Matt Graff
 * v1.0 by Adam Cameron (simplifying logic, making locale-aware)
 * 
 * @param dateString 	 A string containing a date in the current locale (Required)
 * @param datePattern 	 A string containing a date format mask (as per LSDateFormat()) (Required)
 * @return A boolean indicating whether the datestring is in the format specified by datepattern 
 * @author Matt Graff (matt11678@hotmail.com) 
 * @version 1.0, July 25, 2013 
 */
boolean function datePatternMatch(required string dateString, required string datePattern){
	return lsIsDate(arguments.dateString) && compareNoCase(arguments.dateString, lsDateFormat(arguments.dateString, arguments.datePattern) ) == 0;
}
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