Skip to content

Instantly share code, notes, and snippets.

@turtlix
Created May 13, 2016 00:57
Show Gist options
  • Save turtlix/61eb2db53cc8df3f7f0c1df6130dd100 to your computer and use it in GitHub Desktop.
Save turtlix/61eb2db53cc8df3f7f0c1df6130dd100 to your computer and use it in GitHub Desktop.
<?php
function age($date){
$time = strtotime($date);
if($time === false){
return '';
}
$year_diff = '';
$date = date('Y-m-d', $time);
list($year,$month,$day) = explode('-',$date);
$year_diff = date('Y') - $year;
$month_diff = date('m') - $month;
$day_diff = date('d') - $day;
if ($day_diff < 0 || $month_diff < 0) $year_diff-;
return $year_diff;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment