Skip to content

Instantly share code, notes, and snippets.

@rajvanshipradeep15
Created August 2, 2013 06:59
Show Gist options
  • Save rajvanshipradeep15/6137990 to your computer and use it in GitHub Desktop.
Save rajvanshipradeep15/6137990 to your computer and use it in GitHub Desktop.
php calculate age
// to calculate age
$interval = date_diff(date_create(), date_create('2008-01-01 10:30:00'));
echo $interval->format("You are %Y Year, %M Months, %d Days, %H Hours, %i Minutes, %s Seconds Old");
About Date
/* $startYear=strtotime(date("Y-04-1"));
$startYear = date('Y-m-d', $startYear);
// echo "startyear : ". $startYear;
// $startYear = DateTime::createFromFormat('Y-m-d', $startYear);
// echo $testdate = date('Y-m-d' , strtotime('1 year ago'));die;
//to convert from a string to DateTime back to string to change the format
// $startYear = $startYear->format('Y-m-d');
// die;
echo $vardate = $startYear;
$added = "-1 year";
$data = explode("-", $vardate);
// echo "<pre>";
// print_r($data);
// echo "</pre>";
// die;
$date = new DateTime();
$date->setDate($data[0], $data[1], $data[2]);
$date->modify("".$added."");
$day= $date->format("Y-m-d");
// echo $day;die;*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment