Jump to content


Photo

DOB Calculations...


  • Please log in to reply
4 replies to this topic

#1 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 14 July 2006 - 09:12 AM

Hi,
I was wondering how to get a date of birth from a database and calculate it/the year to output an age.
ie: 01/02/1990 - 16 | 01/02/1989 - 17.
but make PHP calculate it.

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 14 July 2006 - 09:38 AM

I might have gone at this the long way around, but hey, it works...
<?php
function age($dob) {
	$date = strtotime($dob);
	$today = strtotime(date("d/m/Y"));
	echo floor(($today - $date) / 31556926);
}

age("16/12/1985"); //Displays 20
?>


#3 xyn

xyn
  • Members
  • PipPipPip
  • Advanced Member
  • 779 posts
  • LocationNorthampton

Posted 14 July 2006 - 09:57 AM

thanks :] if it works it doesn't matter how long it is really.

#4 brown2005

brown2005
  • Members
  • PipPipPip
  • Advanced Member
  • 943 posts

Posted 14 July 2006 - 09:59 AM

yes thanks, i need that code.. very nifty

#5 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 14 July 2006 - 11:52 AM

Looking back on my solution, it's not a very good one, as unix time stamps only start from 01/01/1970 and Negative timestamps are only available on PHP5 and on some *NIX based OS




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users