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!

Validating Dates

Status
Not open for further replies.

Kush

Programmer
Sep 20, 2000
24
0
0
US
I am trying to use the CreateDate(year, month, day) function to create a date after passing it the 3 values and want to throw an error if the date is invalid, e.g, if Feb 30 is passed to it. The problem is that whenever invalid parameters are passed, an error is thrown but I am not able to catch the error and abort. I might not be using the CreateDate appropriately or <CFTRY> and <CFCATCH> properly.

Can someone tell me what could be going wrong?

Thanks.
 
<!--You could try the ISDATE() function...

For example, give the var made with createdate the name
vardate.

Syntax:-->

<cfif ISDATE(#vardate#) is &quot;yes&quot;>
condition here
<cfelse>
another condition here
</cfif>

<!--good luck-->
 
Try:
Code:
<cftry>
  <cfset TheDate=CreateDate(Form.TheYear, Form.TheMonth, Form.TheDay)>
<cfcatch>
  Invalid Date
</cfcatch>
</cftry>
<cfoutput>
  The date is #dateformat(TheDate,&quot;dddd mmmm d, yyyy&quot;)#.
</cfoutput>
Hope this helps.. DarkMan
 
catching errors
go on allaire's site for the doc ;-)
 
They're used like:
Code:
<CFTRY>

  <!--- CODE THAT WILL POSSIBLY PRODUCE AN ERROR --->

  <CFCATCH>
    <!--- CODE TO HANDLE THE ERROR --->
  </CFCATCH>

</CFTRY>
DarkMan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top