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:
Launch code in new window » Download code as text file »
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.
Download Code Snippet ZIP File
Comments (0) | Post Comment | Ask Ben | Permalink | Other Searches | Print Page
There are no comments posted for this web log entry.