Age Calculation

Thread Solved

Join Date: Feb 2008
Posts: 49
Reputation: emhmk1 is an unknown quantity at this point 
Solved Threads: 0
emhmk1 emhmk1 is offline Offline
Light Poster

Age Calculation

 
0
  #1
Nov 3rd, 2009
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...
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 49
Reputation: EvolutionFallen is an unknown quantity at this point 
Solved Threads: 8
EvolutionFallen EvolutionFallen is offline Offline
Light Poster
 
1
  #2
Nov 3rd, 2009
How about converting the date string into a UNIX timestamp, then subtracting that stamp from today's stamp?
Something like:

  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));
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 1,096
Reputation: ardav will become famous soon enough ardav will become famous soon enough 
Solved Threads: 138
ardav's Avatar
ardav ardav is offline Offline
Veteran Poster
 
-1
  #3
Nov 3rd, 2009
Should be clear from the next row but if not:

  1. b_day = strtotime("1/1/1970") //is also in m/d/Y (US) format

@EF - sorry for jumping in.
If you don't reply to your own thread or you can't find the solved link - you're off my Christmas list - permanently! Bah humbug!
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 49
Reputation: emhmk1 is an unknown quantity at this point 
Solved Threads: 0
emhmk1 emhmk1 is offline Offline
Light Poster
 
0
  #4
Nov 3rd, 2009
Thanks guys for the help, sorted now!!

Cheers...
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 49
Reputation: EvolutionFallen is an unknown quantity at this point 
Solved Threads: 8
EvolutionFallen EvolutionFallen is offline Offline
Light Poster
 
0
  #5
Nov 3rd, 2009
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.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:




Views: 296 | Replies: 4
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC