Calculate Age Using a Birth Date
This function gets birth date as an argument and it returns the age of the person;
it's very useful when building communities or social media sites.
[View All Snippets]
[View All Snippets]
Show Plain Text »
- <?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;
- }
- ?>