Easily display your age withour having to update it manually every one year
First, you just include the function below anywhere on your site, preferably on the header file;
<?php
function calculateAge ($birthday) {
list($year,$month,$day) = explode("-", $birthday);
$year_diff = date("Y") - $year;
$month_diff = date("m") - $month;
$day_diff = date("d") - $day;
if ($month_diff < 0) $year_diff--;
elseif (($month_diff == 0) && ($day_diff < 0)) $year_diff--;
return $year_diff;
} ?>
Then, just put this line of code at where you want to display your age;
<?php echo calculateAge("YYYY-MM-DD");?>
Just replace the YYYY-MM-DD part with your birthday date… That’s all!
Comment?
»
Leave a comment
ajwa . Naj . Wawa . 26 . 











