Skip to:
Content
Pages
Categories
Search
Top
Bottom

Reply To: Display age on profile page

@modemlooper

Moderator
//Calculate someone's age based on a date of birth string

$year = date("Y");  // Get this year as a string, date(string format, [timestamp default: now])

$dobtime = strtotime("04/09/1980"); // Get date of birth as a timestamp

$age = $year - date("Y",$dobtime);  // Take advantage of auto conversion to subtract this year from the year of the DOB

$bday = date("m/d/",$dobtime).$year; // Create a timestamp from their month and day of birth combined with this year

if((time()-strtotime($bday))<0) $age = $age - 1; // Compare their bday for this year to current timestamp and subtract one from the year if their birthday has not occurred yet
Skip to toolbar