View comments | RSS feed

IsDate

Description

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

Return value

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

Category

Date and time functions, Decision functions

Syntax

IsDate(string)

See also

CreateDateTime, IsNumericDate, LSDateFormat, LSIsDate, ParseDateTime

Parameters

Parameter Description
string
A string or a variable that contains one.

Usage

This function checks only a U.S. date format. For other date support, see LSDateFormat.

A date/time object falls in the range 100 AD-9999 AD. See "How ColdFusion processes two-digit year values".

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">
<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 9 | ColdFusion 8 | ColdFusion MX 7 | ColdFusion MX 6.1 | ColdFusion MX | Forums | Developer Center | Bug Reporting

Version 6

Comments are no longer accepted for ColdFusion MX. ColdFusion 8 is the current version.

Comments


said on Dec 11, 2003 at 10:21 AM :
IsDate checks non-US dates too. For example, IsDate("21/11/2003") returns true.
No screen name said on Feb 2, 2004 at 9:30 AM :
The IsDate() function says "02/02" is a valid date, which is less than helpful -- should this be evaluated at 02/02/current_year, or as Feb 2002?

Either way, this "valid date" will generate an error when it is used to update a database date column.
halL said on Feb 2, 2004 at 10:25 AM :
The IsDate result indicates that ColdFusion can interpret "02/02" as Feb 2 of the current year.
To insert a date such as this into a data source, use the ParseDate function, as in the following example (tested in ColdFusion MX 6.1):

<cfquery datasource="cfsnippets" name="insert">
INSERT INTO Messages(Message_ID, Thread_ID, Posted)
VALUES (400, 166, #parsedatetime("02/02")#)
</cfquery>
DotSPF said on Aug 29, 2004 at 10:31 AM :
Unfortunately this doesn't check whether a date is actually valid, only correctly formatted. For example the string 2004-02-31 is accepted, but will cause an error if used as part of a CreateDate function.
No screen name said on May 9, 2005 at 6:59 AM :
I must say this is a very creative function.

Which of the following do you think will be recognised as dates?

08F
08A
10P
13

Made your guesses? Check below for the answers:

isDate("08F") = NO
isDate("08A") = YES
isDate("10P") = YES
isDate("13") = NO

forgive me for thinking this is next to useless...
ASandstrom said on May 9, 2005 at 11:00 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.
aawan said on May 10, 2005 at 11:03 AM :
Well that's really helpful.
That's like saying, only pass correctly formatted Numbers to the IsNumeric function, otherwise, we cannot guarantee that you will get the expected result.

Functions like IsDate, IsArray, IsNumeric, are supposed to be validation functions and users expect them to be. It seems that IsDate is an erroneous function, since a user can pass in garbage, yet the function still considers it a valid date.

 

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

Current page: http://livedocs.adobe.com/coldfusion/6/CFML_Reference/functions-pt1128.htm