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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DateCompare? 2

Status
Not open for further replies.

fusionaire

Programmer
May 20, 2000
67
0
0
US
Among the three sites that I am currently responsible for, the client now needs a way to check today's date and year versus a user's input for thier birthday. I have never tried anything like this, and even though I have the CF Bible in hand,reading all about DateCompare, DateDiff and DatePart, I still see no economical way to get the result.<br><br>If anyone has any clues, I would very much appreciate it.
 
Some examples...<br><FONT FACE=monospace><b><br>&lt;cfset thedate=&quot;#dateformat(now())# #timeformat(now())#&quot;&gt;<br><br>&lt;cfif datepart(&quot;m&quot;,thedate) is datepart(&quot;m&quot;,form.date)&gt;<br>Your birthday is this month.<br>&lt;/cfif&gt;<br><br>&lt;cfoutput&gt;<br>You are #datediff(&quot;yyyy&quot;,form.date,thedate) years old.<br><br>You were #datediff(&quot;d&quot;,form.date,thedate) days ago.<br><br>You were born #(&quot;n&quot;,form.date,thedate) minutes ago.<br>&lt;/cfoutput&gt;<br><br>&lt;!--- Compare dates with precision to the day.&nbsp;&nbsp;Precision can also be set for seconds(s), minutes(n), hours(h), months(m) or years (yyyy) ---&gt;<br>&lt;cfswitch expression=#datecompare(form.date,thedate,&quot;d&quot;)#&gt;<br>&nbsp;&nbsp;&lt;cfcase &quot;-1&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;cfoutput&gt;#form.date# is earlier than #thedate#&lt;/cfoutput&gt;<br>&nbsp;&nbsp;&lt;/cfcase&gt;<br>&nbsp;&nbsp;&lt;cfcase &quot;0&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;cfoutput&gt;#form.date# is the same day as #thedate#&lt;/cfoutput&gt;<br>&nbsp;&nbsp;&lt;/cfcase&gt;<br>&nbsp;&nbsp;&lt;cfcase &quot;1&quot;&gt;<br>&nbsp;&nbsp;&nbsp;&nbsp;&lt;cfoutput&gt;#form.date# is later than #thedate#&lt;/cfoutput&gt;<br>&nbsp;&nbsp;&lt;/cfcase&gt;<br>&lt;/cfswitch&gt;</b></font>
 
DM~<br>Thanks again as I think I see a way to apply this in my application. I am still a bit confused, but I will experiment with these ideas. <br>Here is exactly what I am doing:<br>I have a 3 fields that gather the information.<br>year_of_birth<br>day_of_birth<br>month_of_birth<br><br>That is all inputed into a form, which then the user submits.<br><br>I then update a table that contains those fields. What I want to do next is use the ODBCCreateDate(?) and then use a cfif statement.<br><br>What I need it to do is get an exact day and year, and then calculate the age as the result. This way the application knows which pages it will go to next.<br><br>any ideas?<br><br>
 
<FONT FACE=monospace><b>&lt;cfset birthdate=createdate(year_of_birth,day_of_birth,month_of_birth)&gt;<br><br>&lt;cfset diff=#datediff(&quot;yyyy&quot;,birthdate,now()#&gt;<br><br>&lt;cfif diff lt 18&gt;<br>&nbsp;&nbsp;&lt;cflocation url=&quot;child.cfm&quot;&gt;<br>&lt;cfelseif diff ge 18 and diff lt 65&gt;<br>&nbsp;&nbsp;&lt;cflocation url=&quot;adult.cfm&quot;&gt;<br>&lt;cfelse&gt;<br>&nbsp;&nbsp;&lt;cflocation url=&quot;senior.cfm&quot;&gt;<br>&lt;/cfif&gt;<br></b></font><br>Hope this helps...
 
DM<br>That is exactly what I needed! Thank you again!!!!!<br><br>Fusionaire
 
I have been testing this code and now I am bumping into the following problem:<br><br>Whenever I choose a date exactly 16 years ago (in this case, July 13, 1984), I get the following error.<br><br>Error Diagnostic Information<br><br>An error occurred while evaluating the expression: <br><br><br>&nbsp;birthdate=createdate(year_of_birth,day_of_birth,month_of_birth)<br><br><br><br>Error near line 10, column 7.<br>--------------------------------------------------------------------------------<br><br>In the function CreateDate(year, month, day) the combination of the arguments, which are 1984-13- 7, have resulted in an invalid date value. The valid range of dates approximately covers the period between 100 AD and 9999 AD<br><br><br>The error occurred while processing an element with a general identifier of (CFSET), occupying document position (10:1) to (10:71).<br><br><br>Anytime I pick today's date, I get that error also, regardless of what year is chosen.<br><br>Please Advise.<br>
 
It also gives me the same error anytimer I pick the 13th no matter what year it is,
 
fusionaire -<br><br>Sorry about that, I must have dyslexia of the brain...&nbsp;&nbsp;The proper syntax is<br><br><FONT FACE=monospace>&lt;cfset birthdate=createdate(year_of_birth,<b>month</b>_of_birth,<b>day</b>_of_birth)&gt;</font><br><br>I had the month and day reversed in my (hastily written) example....<br>
 
DarkMan~<br><br>Yet again you have saved the day for me!!<br><br>Thanks!!<br><br>Fusionaire
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top