Hi there again everyone,

I've got a form that asks a person's age by offering a dropdown for month, day and year of birth.

A couple of questions further down, it asks them if they have a work permit, but it's only applicable if they are under 18.

If they're over 18, on form process I don't want to even bother with the question. The format that my values are in are as follows:

dob_m = 'Jan'
dob_d = '12'
dob_y = '1970'

Can I use strtotime to determine the age of someone and then decide whether to present the question for asking?

It's a two part problem, I guess. First I have to determine the age, then decide whether to present the question by using a </> determination using the previously calculated age. I've just never worked with the data in this way and am not sure how to get the script to make this decision.

thanks,
json

    You can use strtotime but to make your task a little easier, I would change the values in the month's drop down menu to 1-12 instead of Jan-Dec. Once you do that, you can calculate their age like this:

    $age_in_seconds = time() - mktime(0,0,0,$dob_m,$dob_d,$dob_y);
    $age_in_years = $age_in_seconds / 31536000 ;
    if ($age_in_years >= 18) {
    print "You are 18 or older.  Do you have a work permit? <br><form action='page2.php'>";
    print "Yes <input type=radio name=permit value='Y'> No <input type=radio name=permit value='N'><input type=submit value='Go'></form>";
    }
    else { print "You are under 18.  No further questions."; }
    

      Hi there etully,

      It worked excellently, but I have one more question:

      It gives the age(if I print it) in the following format:

      33.270010495941

      With the code you provided, how would I alter it if I wanted it to round down to the nearest whole number?

      Thanks very much for the help you've already provided.

      thanks,
      json

        floor()

        Google for:
        round down php

          Write a Reply...