Skip to main content
Participant
April 17, 2006
Answered

<cfif IsDate(FORM.theTestValue)> vs <cfif Isnot Date(FORM.theTestValue)>

  • April 17, 2006
  • 3 replies
  • 753 views

i am very new to CF.
can anyone explain to me what this

<cfif IsDate(FORM.theTestValue)> vs <cfif Isnot Date(FORM.theTestValue)>


means: and what it is used for?
how is it beneficial?
This topic is closed to new replies. Start a new post to keep the conversation going.
Correct answer JMGibson3
If you were to blindly take whatever someone keyed on a Form and try to insert it into a Database column defined as type=DateTime, your SQL would crash. If you check it first to ensure it's a date you can bypass the Insert and send back a "pretty" message (xxxx must be a valid date) to the user rather than the default crash message

3 replies

Participant
April 18, 2006
This is a good test to perform if you don't want your app to crash when you try to use the variable in a date function.?
OK
but what is this is date used for?
or commonly used for?


JMGibson3Correct answer
Participating Frequently
April 18, 2006
If you were to blindly take whatever someone keyed on a Form and try to insert it into a Database column defined as type=DateTime, your SQL would crash. If you check it first to ensure it's a date you can bypass the Insert and send back a "pretty" message (xxxx must be a valid date) to the user rather than the default crash message
Inspiring
April 17, 2006
quote:

Originally posted by: tiffianypeck

i am very new to CF.
can anyone explain to me what this
<cfif IsDate(FORM.theTestValue)> vs <cfif Isnot Date(FORM.theTestValue)>

means: and what it is used for?
how is it beneficial?


This
<cfif IsDate(FORM.theTestValue)>
returns true if form.theTestValue is a valid date.

This
<cfif Isnot Date(FORM.theTestValue)>
should be
<cfif not IsDate(FORM.theTestValue)>
will return false if form.theTestValue is a valid date.

This is a good test to perform if you don't want your app to crash when you try to use the variable in a date function.