944,134 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 733
  • PHP RSS
Nov 3rd, 2009
0

Age Calculation

Expand Post »
Hi guys, i have been trawling around looking for a decent and simple way of working out an age from a birthday.

The way i'm working is a date of birth is added to a database then when pulled we echo the actual age and not the d.o.b.

It's probably quite simple but i can't seem to figure it out, Also there may not be an actual day eg 06/2009 instead of 13/06/2009 if you see my meaning.

Any direction would be great!

Thanks again...
Similar Threads
Reputation Points: 11
Solved Threads: 7
Junior Poster
emhmk1 is offline Offline
107 posts
since Feb 2008
Nov 3rd, 2009
1
Re: Age Calculation
How about converting the date string into a UNIX timestamp, then subtracting that stamp from today's stamp?
Something like:

PHP Syntax (Toggle Plain Text)
  1. $b_day = strtotime("1/1/1970"); // UNIX time for birthday
  2. $today = strtotime(date("m/d/Y"));
  3. $age = date("your formatting string here", $today - $b_day));
Reputation Points: 40
Solved Threads: 31
Junior Poster
EvolutionFallen is offline Offline
198 posts
since Aug 2009
Nov 3rd, 2009
-1
Re: Age Calculation
Should be clear from the next row but if not:

PHP Syntax (Toggle Plain Text)
  1. b_day = strtotime("1/1/1970") //is also in m/d/Y (US) format

@EF - sorry for jumping in.
Sponsor
Featured Poster
Reputation Points: 1067
Solved Threads: 955
Disgraced Poster
ardav is offline Offline
6,728 posts
since Oct 2006
Nov 3rd, 2009
0
Re: Age Calculation
Thanks guys for the help, sorted now!!

Cheers...
Reputation Points: 11
Solved Threads: 7
Junior Poster
emhmk1 is offline Offline
107 posts
since Feb 2008
Nov 3rd, 2009
0
Re: Age Calculation
You're welcome emhmk1.
No problem ardav =) I was in a rush so I was worrying more bout typing the code than placing comments. Thanks for filling it in.
Reputation Points: 40
Solved Threads: 31
Junior Poster
EvolutionFallen is offline Offline
198 posts
since Aug 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Parse Error in Class
Next Thread in PHP Forum Timeline: if isset ==





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC