Member Avatar

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";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.