Jump to content

[SOLVED] Calculate Age Based on Date of Birth


stevesimo

Recommended Posts

Hi, I am trying to validate whether or not a date of birth entered in dd/mm/yyyy format is between 16 and 69 years old.  Suppose we have todaysdate = 18/04/2007

 

The minimum allowed date of birth would be 18/04/1991 and the maximum allowed date of birth would be 18/04/1938.  I have looked at using strtotime but this only does dates from 1970 (I think)

 

Can anyone help me with this as I am really stuck and not sure how to compare the dates.

 

Thanks

 

Steve (Blackpool)

<?php

list($d, $m, $y) = explode("/", $date);
$time = mktime(0, 0, 0, $m, $d, $y);
$age = floor((now() - $time) / 31557600); //This number is the number of secs in a year
if($age < 69  &&  $age > 16)
echo "Good age!";
else
echo "Bad age!";

?>

 

 

Orio.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.