954,587 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Check Age

Hi All

I am trying to add a no under 18's feature to my register page. I have got a simple function which uses the year of birth but I am not sure what to do for the day and month.
Here is the code. If someone could help me with the day and month, I would be very grateful.
Thanks in advance

<?php

function GetAge($DOB) {

  list($Year, $Month, $Day) = explode("-",$DOB);

  $YearDifference  = date("Y") - $Year;

  $MonthDifference = date("m") - $Month;

  $DayDifference   = date("d") - $day;

  if ($DayDifference < 0 || $MonthDifference < 0) {

    $YearDifference--;

  }

  return $YearDifference;

}


$year = 1995;
if(GetAge($year)<18)
{
    echo "Too Young";
}
else echo "Old enough";
doctorphp
Junior Poster in Training
67 posts since Apr 2010
Reputation Points: 10
Solved Threads: 0
 

You're probably better off using timestamps. Have a look at this tutorial:

http://www.dreamincode.net/forums/topic/19953-calculating-age-tutorial/

chrishea
Nearly a Posting Virtuoso
1,428 posts since Sep 2008
Reputation Points: 210
Solved Threads: 230
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: