1

So I am working in a classic ASP environment with a MySQL database. I want to add in a query to a form so that it adds an age restriction of being at least 13 years old. Here's what I was attempting to throw into the code:

If DATEDIFF("yyyy",now(), Person_DateOfBirth) > 12 Then
    Response.write "You are over 12"
Else
    Response.write "You are under 12"
End if

I am attempting to use the Datediff attribute to limit the age result. The now() variable is set as the current date, the Person_DateOfBirth variable is the selection that they choose on the form. Then im attempting to write a response on the screen depending on the value from the diffdate.

When this code is inserted into the query, there is no response at all.

I need help rewriting this code so it functions correctly, or if someone has another resolution in Classic ASP, that would be great.

Thanks!

1
  • Where is Person_DateOfBirth defined and assigned a value? Is it in a valid date format? Try using CDate to cast it to a date object. Or IsDate to make sure it is a valid date.
    – Jon P
    Apr 24, 2015 at 3:17

1 Answer 1

1

The code requires the ASP Form Collection to access the "Person_DateOfBirth" variable submitted through the form.

Example Code

default.asp

<html>
    <body>
        <form action="submit.asp" method="post">
        My age is <input type="text" name="Person_DateOfBirth">
        <input type="submit" value="Submit">
        </form>
    </body>
</html>

submit.asp

<%
If DATEDIFF("yyyy",now(), request.Form("Person_DateOfBirth")) > 12 Then
    Response.write "You are over 12"
Else
    Response.write "You are under 12"
End if
%>
1
  • Hi @jblackmon if this or any answer has solved your question please consider accepting it by clicking the check-mark. This indicates to the wider community that you've found a solution and gives some reputation to both the answerer and yourself. There is no obligation to do this. Apr 24, 2015 at 3:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.