Coldfusion’s IsDate() method has fooled me for the last time. Where as any self respecting programmer would think that a method name IsDate, that returns a value of ‘yes’ or ‘no’ no less, would be checking to ensure that the date in fact is valid. That is where I was wrong. Looking at the method itself I find that IsDate doesn’t validate a date at all. What it actually checks is if a string can be converted into a date value. That pretty much renders this method useless as just about any string could return true.
Not to worry though, there is a solution. Using the IsValid() method with the type rule “USDate” and passing your date string as parameters. This will actually check the date submitted against the calender and validate correctly. Why IsDate() doesn’t behave this way is beyond reason.
<!---
Proper Date Validation
--->
<cfset variables.date_string = "7/20/1980" />
<cfoutput>#IsValid("USDate",variables.date_string)#</cfoutput>
<!--- Outputs "YES" --->











November 2, 2009
Development