A friend of mine gave me this code to show a person’s age from their birth date and it works fine, except, when there is no birth date it shows Birthdate: (43). So long story short, does anyone know how I can get it to display Unknown if there is no date added for that person?
Here is the code I’m using:
// GET AGE FROM BIRTHDATE ($age)
$bdate = $row_getIdol["bd"]; // FROM SQL
if($bdate == 0){ $nodate = 1; }
$bdate = strtotime( $bdate );
$birthday = date("n/j/Y",$bdate); //must be as m/d/yyyy
$bday = explode("/", $birthday); //parse
$b_mm = $bday[0]; //birthday month
$b_dd = $bday[1]; //birthday day
$b_yyyy = $bday[2]; //birthday year
//compare timestamps of mm/dd for birthday and today
$bday_mm_dd = mktime(0,0,0,$b_mm,$b_dd,0);
$today_mm_dd = mktime(0,0,0,date("m"),date("d"),0);
$age = date("Y", time()) - $b_yyyy;
if ($bday_mm_dd > $today_mm_dd) {
//birthday hasnt happened yet this year
$age = $age - 1;
}
// END GET AGE FROM BIRTHDATE