need healp age calculator

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
greedyisg00d
Forum Commoner
Posts: 42
Joined: Thu Feb 12, 2009 2:48 am

need healp age calculator

Post 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
User avatar
angelicodin
Forum Commoner
Posts: 81
Joined: Fri Nov 13, 2009 3:17 am
Location: Oregon, USA

Re: need healp age calculator

Post 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.
User avatar
Grizzzzzzzzzz
Forum Contributor
Posts: 125
Joined: Wed Sep 02, 2009 8:51 am

Re: need healp age calculator

Post 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
greedyisg00d
Forum Commoner
Posts: 42
Joined: Thu Feb 12, 2009 2:48 am

Re: need healp age calculator

Post by greedyisg00d »

Thanks can you post some sample codes that I can work on. I am currently reading the date manual
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Post by Jonah Bron »

Code: Select all

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

It's that easy :)
Post Reply