Skip to content

Instantly share code, notes, and snippets.

@jackabox
Created December 10, 2013 18:40
Show Gist options
  • Save jackabox/7895757 to your computer and use it in GitHub Desktop.
Save jackabox/7895757 to your computer and use it in GitHub Desktop.
Working out the age from a DOB
<?php
//date in mm/dd/yyyy format; or it can be in other formats as well
$birthDate = '11/05/1992';
//explode the date to get month, day and year
$birthDate = explode("/", $birthDate);
//get age from date or birthdate
$age = (date("md", date("U", mktime(0, 0, 0, $birthDate[0], $birthDate[1], $birthDate[2]))) > date("md") ? ((date("Y")-$birthDate[2])-1):(date("Y")-$birthDate[2]));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment