Page 1 of 1

need healp age calculator

Posted: Tue Nov 17, 2009 10:58 pm
by greedyisg00d
I need some help creating an age calculator which will display your exact date example:

Birth date: 2000-11-03
Date Today: 2009-11-18
Exact age: 9 years 0 months 15 days

Any idea on how can this be done? Sample codes is much appreciated

Thanks

Re: need healp age calculator

Posted: Wed Nov 18, 2009 12:54 am
by angelicodin
Well there are quite a few ways to go about this.
To get the person's B-Day you could do a two page deal with a form and post, or single page using get (depending on how your are going to use it).
For getting today's date is vary easy "date()" then you just input how you want it to be formatted. Click HERE for the date manual.
After that bit of information it's just some simple math. ;p

If you are trying to learn, HTH, otherwise I can whip up an example for you.

Re: need healp age calculator

Posted: Wed Nov 18, 2009 3:39 am
by Grizzzzzzzzzz
greedyisg00d wrote:I need some help creating an age calculator which will display your exact date example:

Birth date: 2000-11-03
Date Today: 2009-11-18
Exact age: 9 years 0 months 15 days

Any idea on how can this be done? Sample codes is much appreciated

Thanks

get the person to post their Date of Birth

use the date function to get todays date

http://php.net/manual/en/function.date.php

format it in such a way that it's identical to the way they input it and then it's just simple maths

Re: need healp age calculator

Posted: Wed Nov 18, 2009 7:09 pm
by greedyisg00d
Thanks can you post some sample codes that I can work on. I am currently reading the date manual

Posted: Wed Nov 18, 2009 8:21 pm
by Jonah Bron

Code: Select all

$age_in_seconds = time() - strtotime($birthday);
time()
strtotime()

It's that easy :)