This really isn't news; I am just writing this down to try and drill it into my head. I just spend 10 minutes debugging some old Caching code that uses a CacheUntil date/time stamp. When setting the CacheUntil value, I was using the CreateTimeSpan() to create a future date:
(Now() + CreateTimeSpan( 0, 0, 5, 0 ))
The cache never seemed to be expiring. As part of the logic, the caching controller was checking to see if the CacheUntil value was a date since non-date values would denote a non-expiring data store. It was using ColdFusion's IsDate() function to check the CacheUntil value; IsDate() is great, but it ignores numeric date/time representations. As such, the date I created using the CreateTimeSpan() math was being ignored:
<!--- Get a date that is 10 minutes in the future. ---> <cfset objFuture = (Now() + CreateTimeSpan( 0, 0, 10, 0 )) /> IsDate() :: #IsDate( objFuture )#<br /> IsNumericDate() :: #IsNumericDate( objFuture )#<br />
When we run the above code, we get the following output:
IsDate() :: NO
IsNumericDate() :: YES
As you can see, the date math produced a value that IsDate() did not recognize but IsNumericDate() did. I ran into this issue almost three years ago, but I still forget to use IsNumericDate() as my default date/time filter. Remember, remember, remember - just start using IsNumericDate()!
Want to use code from this post? Check out the license.