View comments | RSS feed

IsNumericDate

Description

Evaluates whether a real number is a valid representation of a date (date/time object).

Returns

True, if the parameter represents a valid date/time object; False, otherwise.

Category

Date and time functions, Decision functions

Function syntax

IsNumericDate(number)

See also

IsDate, ParseDateTime

Parameters

Parameter Description

number

A real number

Usage

ColdFusion, by default, evaluates any input parameter and attempts to convert it to a real number before it passes the parameter to the IsNumericDate function. As a result, parameter values such as 12/12/03 and {ts '2003-01-14 10:04:13'} return True, because ColdFusion converts valid date string formats to date/time objects, which are real numbers.

Example

<h3>IsNumericDate Example</h3>
<cfif IsDefined("form.theTestValue")>
<!--- test if the value represents a number or a pre-formatted Date value --->

   <cfif IsNumeric(form.theTestValue) or IsDate(form.theTestValue)>
<!--- if this value is a numericDate value, then pass --->
      <cfif IsNumericDate(form.theTestValue)>
         <h3>The string <cfoutput>#DE(form.theTestValue)#</cfoutput> can be converted to a valid numeric date</h3>
      <cfelse>
         <h3>The string <cfoutput>#DE(form.theTestValue)#</cfoutput> can not be converted to a valid numeric date</h3>
      </cfif>
   <cfelse>
      <h3>The string <cfoutput>#DE(form.theTestValue)#</cfoutput> is not a valid numeric date</h3>
   </cfif>

</cfif>

<form action="#cgi.script_name#" method="POST">
<p>Enter a value, and discover if 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


MikerRoo said on Oct 8, 2005 at 10:44 PM :
IsDate(), IsValid("date"), and IsNumericDate() all report true for a certain invalid months.


Also the document for IsDate() says that the date must be >= 100 AD. This does not seem to be true.

Here are some test strings and their results:

String IsDate() IsValid() IsNumericDate()
-------------------------- -------- --------- ---------------
{ts '0000-00-00 00:00:00'} YES YES YES
{ts '0090-00-00 00:00:00'} YES YES YES
{ts '2000-13-13 00:00:00'} YES YES YES
{ts '2000-13-45 00:00:00'} NO NO NO
{ts '2000-12-13 25:00:00'} NO NO NO
{ts '2000-12-13 22:66:00'} NO NO NO
{ts '2000-12-13 22:00:66'} NO NO NO
{ts '0090-11-11 11:11:11'} YES YES YES

 

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/00000526.htm