View comments | RSS feed

IsDate

Description

Determines whether a string or Java object can be converted to a date/time value.

Returns

True, if string can be converted to a date/time value; False, otherwise. ColdFusion converts the Boolean return value to its string equivalent, "Yes" or "No."

Category

Date and time functions, Decision functions

Function syntax

IsDate(string)

See also

CreateDateTime, IsNumericDate, IsValid, LSDateFormat, LSIsDate, ParseDateTime

Parameters

Parameter Description

string

A string or a variable that contains one.

Usage

This function checks against U.S. date formats only. For other date support, see LSDateFormat.

A date/time object falls in the range 100 AD-9999 AD.

Example

<h3>IsDate Example</h3>
<cfif IsDefined("FORM.theTestValue")>
   <cfif IsDate(FORM.theTestValue)>
   <h3>The string <cfoutput>#DE(FORM.theTestValue)#</cfoutput> 
    is a valid date</h3>
   <cfelse>
   <h3>The string <cfoutput>#DE(FORM.theTestValue)#</cfoutput> 
    is not a valid date</h3>
   </cfif>
</cfif>
<form action = "isDate.cfm" method="post">
<p>Enter a string, find whether it can be evaluated to a date value.
<p><input type = "Text" name = "TheTestValue" value = "<cfoutput>#Now()#
</cfoutput>"> <input type = "Submit" value = "Is it a Date?" name = ""> </form>

ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | KnowledgeBase | Bug Reporting

Version 7

Comments


ASandstrom said on May 9, 2005 at 11:05 AM :
Passing numeric data to the ColdFusion IsDate and ParseDateTime functions can yield unexpected results. For example, IsDate may return TRUE for numeric data that are not dates.
To work around this behavior, it is always advisable to only pass string data in a supported format to the IsDate and ParseDateTime functions, or, generate date-time data using the Now or CreateDate functions.
sivakarthikeyan said on Sep 13, 2007 at 3:12 AM :
For a String " 16A244/5" isdate (16A244/5) returns true... It means the string entered is date ..
Please be aware before using this function..
halL said on Sep 18, 2007 at 7:01 AM :
sivakarthikeyan is correct.
It might be helpful to explain the reason this works.
I believe the following happens when ColdFusion processes isdate (16A244/5)
ColdFusion interprets the parameter as an expression, not a string and is evaluated as a division operation on a hexadecimal number.
(It would do so even if the parameter were in quotation marks.)
The division is performed, and then the IsDate function determines whether the resulting value, a number, can be converted to a date.
Numbers can be converted to dates, so the function returns true.

 

RSS feed | Send me an e-mail when comments are added to this page | Comment Report

Current page: http://livedocs.adobe.com/coldfusion/7/htmldocs/00000518.htm