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;
}

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