You need to determine whether a string or numeric value is a valid date object.

Use IsDate() or LSIsDate() for strings, or IsNumericDate() for numeric values. The IsDate() function returns True if the specified string can be converted to a valid date/time object. Be sure to enclose literal dates in quotation marks.

<cfoutput>
<cfset x="12-31-2002">
#isDate(x)#<BR>
#isDate('12/31/2002')#<BR>
#isDate('Dec 31, 2002')#<BR>
#isDate('13/31/2002')#<BR>
#isDate('19:00')#<BR>
#isDate('7pm')#
</cfoutput>

You should be aware that the IsDate() function only works with dates formatted for the U.S. locale. If you have a date formatted using a different locale, you should use the LSIsDate() function. It returns True if the specified date can be converted to a date/time object in the current locale or False if not.

If you need to determine whether a numeric value (real number) is a valid date/time object, you can use the IsNumericDate() function. Like IsDate(), it returns True if the value you pass to it can be converted to a date/time object.

<cfoutput>
#isNumericDate(37621.79167)#<BR>
#isNumericDate(-1)#
</cfoutput>

Because isNumericDate() operates on numeric values, it can be used in any locale.

This question was written by Rob Brooks-Bilson
It was last updated on January 5, 2006.

Categories

Dates/Times

Comments

comments powered by Disqus