PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
function ParseTimeStamp($TimeStamp)
{
$Year = substr($TimeStamp, 0, 4);
$Month = substr($TimeStamp, 4, 2);
$Day = substr($TimeStamp, 6, 2);
$Hour = substr($TimeStamp, 8, 2);
if ($Hour >= 12) $Meridiem = 'PM'; else $Meridiem = 'AM';
if ($Hour > 12) $Hour = $Hour - 12;
$Minute = substr($TimeStamp, 10, 2);
$Second = substr($TimeStamp, 12, 2);
$TimeStamp = array(); // Clear the variable to a null state
$TimeStamp['Year'] = $Year;
$TimeStamp['Month'] = $Month;
$TimeStamp['Day'] = $Day;
$TimeStamp['Hour'] = $Hour;
$TimeStamp['Meridiem'] = $Meridiem;
$TimeStamp['Minute'] = $Minute;
$TimeStamp['Second'] = $Second;
$TimeStamp['YYYYMMDD'] = $Year . $Month . $Day;
return $TimeStamp;
}
function IsOldEnough($TimeStamp, $DOB, $MOB, $YOB) //current timestamp, day of birth, month of birth, year of birth
{
$TimeStamp = ParseTimeStamp($TimeStamp);
if (($TimeStamp['Year'] - $YOB) > 17){return true;} // if current year - year of birth > 18 return true
if ((($TimeStamp['Year'] - $YOB) == 17) and ($MOB > $TimeStamp['Month'])){return true;} // if was born after this month 17 years ago
if ((($TimeStamp['Year'] - $YOB) == 17) and ($MOB = $TimeStamp['Month']) and ($DOB >= $TimeStamp['Day'])){return true;} // if was born this month and on or after this day 17 years ago
return false;
}
?>
Ya'all are free to use this in your own scripts if you want.
<?php
function IsOldEnough($DOB, $MOB, $YOB) //current timestamp, day of birth, month of birth, year of birth
{
$TimeStamp = ParseTimeStamp($TimeStamp);
if ((date("Y") - $YOB) > 17){return true;} // if current year - year of birth > 18 return true
if (((date("Y") - $YOB) == 17) and ($MOB > date("m"))){return true;} // if was born after this month 17 years ago
if (((date("Y") - $YOB) == 17) and ($MOB = date("m")) and ($DOB >= date("d"))){return true;} // if was born this month and on or after this day 17 years ago
return false;
}
?>