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)

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.