Quick Note On IsDate() vs. IsNumericDate()

Posted August 30, 2006 at 3:50 PM by Ben Nadel

Tags: ColdFusion

After my post yesterday on date math, someone sent me a question about IsDate() vs. IsNumericDate(). I briefly touch on the use of IsNumericDate() to determine if you have a numeric date, but I was not clear on exactly how it works. IsDate() takes a date/time object. IsNumericDate() takes a number. There are some caveats here. Since IsNumericDate() requires a number, if you send it a date/time object, ColdFusion will automatically convert the date/time object to a number, therefore allowing it to work. IsDate(), on the other hand, takes a date/time object and will NOT be true if passed a number, even if that number represents a date.

Take a look at this example:

• <!--- Get date/time object. --->
• <cfset dtNow = Now() />
•
• <!--- Get NUMERIC date value. --->
• <cfset flNow = (dtNow * 1) />
•
• <!--- Output the date and test methods. --->
• #DateFormat( dtNow )# - #IsDate( dtNow )# - #IsNumericDate( dtNow )#
•
• <!--- Output the numeric date and test methods. --->
• #DateFormat( flNow )# - #IsDate( flNow )# - #IsNumericDate( flNow )#

In that second line, just notice that I am multiplying the date by 1. This forces ColdFusion to convert the date/time object to a number. The code produces this output:

30-Aug-06 - YES - YES

30-Aug-06 - NO - YES

As you can see, a standard date/time object will return true for BOTH IsDate() and IsNumericDate(). A numeric date will return true for IsNumericDate(), but FALSE for IsDate(). Sorry if I was unclear about this before. As a safe guard, if you are working on a page where you might be working with numeric dates, I would recommend always using IsNumericDate() as it will give you the most useful responses.

Looking For a New Job?

25% of job board revenue is donated to Kiva. Loans that change lives - Find out more »

Aug 17, 2010 at 10:58 AM // reply »

Ben, this article completely solved the issue I was having. Thanks for the great work, keep it up!

One note: am I misreading the CF :iveDocs, or does their note on the isDate() function specifically say it WILL work when passed a string, which obviously isn't the case since it needs a date object?

Aug 17, 2010 at 9:06 PM // reply »

@Michael,

isDate() will work with a string - but, it won't work with a string that represents a number... is what I think they are saying. So, for example, this will return false:

isDate( "123" )

... but this will return true:

isDate( "jun 1, 2010" )

... both of which are strings. Of course, I might be misunderstanding what the docs are saying.

Comment Etiquette: Please do not post spam. Please keep the comments on-topic. Please do not post unrelated questions or large chunks of code. And, above all, please be nice to each other - we're trying to have a good conversation here.

Please review the following issues:

 Author Name: Author Email: Author Website: Comment: Supported HTML tags for formatting: bold   italic   code Remember my information Subscribe to comments Send me a copy of this comment
Ben Nadel's Company - Epicenter Consulting Recent Blog Comments
Dec 11, 2013 at 10:02 PM
Setting ETag Headers Regardless Of File Content In ColdFusion
Hey Ben, got a quick question for you. I have added a cache manifest file for HTML5 coding and made use of the cfcache tag as such; placed above the body tag. When placing the cfcache with the funct ... read »
Dec 11, 2013 at 4:27 PM
Creating A Custom Show / Hide Directive In AngularJS
This does not work for me. Tried everything as is. ... read »
Dec 11, 2013 at 12:23 PM
Preloading Data Before Executing ngInclude In AngularJS
You could simply use a variable for the src attribute that will be published after the data is loaded and a ng-hide to not show the container while loading the html, which will be switched by the onl ... read »
Dec 11, 2013 at 3:47 AM
ColdFusion 10 - An Augmented Virtual File System (VFS)
I recently found the VFS in both ColdFusion 9 and 10 has some weird performance curves when writing a lot of in-memory files. ( I tried this because I wanted to create a high performance log entry w ... read »
Dec 10, 2013 at 1:00 PM
Quiet: The Power Of Introverts In A World That Can't Stop Talking By Susan Cain
Wonderful insights of your own here. Would love to read this book. Each day of our life we are surrounded with both introverts and extroverts.,, we consciously or subconsciously learn of people every ... read »
Dec 10, 2013 at 12:36 PM
The Processing Instruction Target Matching "[xX][mM][lL]" is Not Allowed
Thanks a lot Ben! Can't count the times i've googled your blog! ... read »
Dec 10, 2013 at 9:31 AM
Changes In Transclude() Function Availability In AngularJS 1.2
With Angular it seems more powerful but less mature as a platform. One of the struggles CFML has is there are not as many solutions as richly supported by developers as WordPress. We have some CMS so ... read »
Dec 9, 2013 at 4:53 PM
Using Track-By With ngRepeat In AngularJS 1.2
Make sure that you put the "track by" syntax after any filters. https://github.com/tastejs/todomvc/pull/726#issuecomment-28817720 ... read »
InVision App - Prototyping Made Beautiful With Prototyping Tools