Strings unintentionally interpreted as DateTime values in comparisons
Issue
Short strings not meant to be "DateTime" values may be evaluated as "DateTime" values in string comparisons.
For instance, a single "A" or "P" can be interpreted as an AM or PM. This interpretation may cause strings which were not intended to be "DateTime" values to be treated as if they were. For example, the following are all TRUE conditions:
| <CFIF œ12/25/00 LT œ7/4/01> | December 25, 2000 is before July 4, 2001 |
| <CFIF œ2am LT œ03:00> | 2:00am is earlier than 3:00am |
| <CFIF œ1a EQ œ01:00> | 1:00am is 1:00am |
| <CFIF œ1P GT œ2A> | 1:00pm is later than 2:00am (probably not what was intended if 1P and 2A are not time values) |
Solution
Use the IsDate() string function (see ColdFusion documentation) to evaluate whether strings are "DateTime" values, or else add additional characters to both strings before comparison to prevent them from being unintentionally evalutaed as "DateTime" strings.
| <CFIF œ1P&xx GT œ2A&xx> | is now FALSE |
| <CFSET alpha = œ2a>
<CFIF IsDate(alpha)> Warning “ variable alpha is a date</CFIF> |
Example of testing for a date value with IsDate()
In this case, alpha is interpreted as a date value (02:00am) |
This content requires Flash
To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.
Download the free Flash Player now!
