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!

Date

Status
Not open for further replies.

WannaLearn

Programmer
Jul 10, 2001
210
0
0
US
Is there anything wrong with this bit of code? I always get an error when someone tries to pass the date as 2/29/2005 or 2/30/2005.

<cfif myYear neq "" and myMonth neq "" and myDay neq "">
<cfset myDOB = myYear & "/" & myMonth & "/" & myDay>
<cfif not listfind("4,6,9,11",myMonth) and myDay neq "31">
<cfset myDOB = DateFormat(myDOB, "yy/mm/dd")>
<cfelseif not listfind("29,30,31",myDay) and myMonth neq "2">
<cfset myDOB = DateFormat(myDOB, "yy/mm/dd")>
<cfelse>
<cfset myDOB = "">
</cfif>
<cfelse>
<cfset myDOB = "">
</cfif>


Thanks.
 
February 29 is only valid on leap years and February 30 is never valid... Try this code..

Code:
<cfif isNumeric(myYear) neq "" and isNumeric(myMonth) neq "" and isNumeric(myDay) neq "">
  <cfset firstday = myMonth & "/1/" & myYear>
  <cfif daysinmonth(mymonth) lt myDay>
  <cfset myDOB = myMonth & "/" & myDay & "/" & myYear>
    <cfif not listfind("4,6,9,11",myMonth) and myDay neq "31">
      <cfset myDOB = DateFormat(myDOB, "yy/mm/dd")>
    <cfelseif not listfind("29,30,31",myDay) and myMonth neq "2">
      <cfset myDOB = DateFormat(myDOB, "yy/mm/dd")>
    <cfelse>
      <cfset myDOB = "">
    </cfif>
  <cfelse>
    <!--- the day specified is greater than the number of days in the specified month --->
    <cfset myDOB = "">
  </cfif>
<cfelse>
  <cfset myDOB = "">
</cfif>

In reality though, this should work as well..

Code:
<cfif isNumeric(myYear) neq "" and isNumeric(myMonth) neq "" and isNumeric(myDay) neq "">
  <cfset firstday = myMonth & "/1/" & myYear>
  <cfif daysinmonth(mymonth) lt myDay>
    <cfset myDOB = myMonth & "/" & myDay & "/" & myYear>
    <cfset myDOB = DateFormat(myDOB, "yy/mm/dd")>
  <cfelse>
    <!--- the day specified is greater than the number of days in the specified month --->
    <cfset myDOB = "">
  </cfif>
<cfelse>
  <cfset myDOB = "">
</cfif>


ALFII.com
---------------------
If this post answered or helped to answer your question, please reply with such so that forum members with a similar question will know to use this advice.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top