Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Check for valid date, if not valid create one for them 1

Status
Not open for further replies.

DrumAt5280

Technical User
Sep 8, 2003
194
0
0
US
I have an input date field along side a pop-up calendar so the user can either pick from the pop-up calendar or type the date in too.

When a user types in a date that can not be converted to a date that CF understands it throws an error - which makes sense.

Is there a way i can check for a valid date, and if it is not a valid date format can i set a valid one for them?

I was thinking of something like this even though there is no such tag "ISDATE":

<cfif ISDATE('FORM.date')>
<CFSET Date= #FORM.date#>
<cfelse>
<cfset Date = now()>
</cfif>

Thanks!
 
isdate is a valid function, i think your syntax is off


If you don't ask the right questions, you don't get the right answers. A question asked in the right way often points to its own answer. Asking questions is the ABC of diagnosis. Only the inquiring mind solves problems.

-Quote by Edward Hodnett
 
Wow, i was just guessing and i got it right. I looked thru the live docs but i must have not looked hard enough.

Thanks!
 
If I am not mistaken, IsDate() would return true if date is passed as 12/06 which it would consider as december of 2006,, but this would definitely fail in an SQL insert if date field is defined, so you just need to be careful.
 
12/06 is December 6 of the current year according to livedocs. but yes it does return true it isn't a great function.

If you don't ask the right questions, you don't get the right answers. A question asked in the right way often points to its own answer. Asking questions is the ABC of diagnosis. Only the inquiring mind solves problems.

-Quote by Edward Hodnett
 
liveDocs said:
The IsDate result indicates that ColdFusion can interpret "02/02" as Feb 2 of the current year.
To insert a date such as this into a data source, use the ParseDate function, as in the following example (tested in ColdFusion MX 6.1):

<cfquery datasource="cfsnippets" name="insert">
INSERT INTO Messages(Message_ID, Thread_ID, Posted)
VALUES (400, 166, #parsedatetime("02/02")#)
</cfquery>

If you don't ask the right questions, you don't get the right answers. A question asked in the right way often points to its own answer. Asking questions is the ABC of diagnosis. Only the inquiring mind solves problems.

-Quote by Edward Hodnett
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top