464,491 Members | 961 Online
Need help? Post your question and get tips & solutions from a community of 464,491 IT Pros & Developers. It's quick & easy.

# User input his/her date of birth and php script calculate how old person is??

 P: 1 Hello ! I´m having problem with this. I already created index.html document which allows user to input his/her date of birth. It looks like this : Expand|Select|Wrap|Line Numbers

How old are you ??

Your name
Your last name Input day (1-31) Input month (1-12) Input year (exmp. 1970.)

....and calculate.php which should calculate how person is old look like this: Expand|Select|Wrap|Line Numbers YOUR AGE  BACK

Current date:

Person   have/has   years,  months and  days.
When I input birth year for example 17.6.1988. i get this result : Person John have/has 22 years, -1 months and 3 days. which is obviously wrong. Does anyone know how to solve this problem ?? This is my college homework and I need answer fast , so if anyone could be kind and solve this I would appreciate it a lot. Thanks in advance and sorry for my bad english . :) May 20 '10 #1

#### ✓ answered by code green

I would try a slightly different route:
Convert the dates into unix timestamps - strtotime() will do this.
Do all the calculations in seconds.

Then convert back into human friendly time - something like
divide by 31536000 = number of seconds in a year.

Admittedly gets trickier if you need months because of varying length.
i think php has a function to do this, or something similar

 Expert 100+ P: 1,726 I would try a slightly different route: Convert the dates into unix timestamps - strtotime() will do this. Do all the calculations in seconds. Then convert back into human friendly time - something like divide by 31536000 = number of seconds in a year. Admittedly gets trickier if you need months because of varying length. i think php has a function to do this, or something similar May 20 '10 #2