age.php
· 458 B · PHP
Raw
<?php
# Add the time for a more accurate calculation.
# The time format must be a string if it begins with a zero (0)
function age($year, $month, $day, $time = null) {
if(!is_numeric($year) OR !is_numeric($month) OR !is_numeric($day)) {
return 'XX';
} else {
$diff = date_diff(date_create($year.'-'.$month.'-'.$day . (empty($time) ? null : ' '.$time)), date_create(date('Y-m-d'.(empty($time) ? null : ' Hi'))));
return $diff->y;
}
}
?>
| 1 | <?php |
| 2 | |
| 3 | # Add the time for a more accurate calculation. |
| 4 | # The time format must be a string if it begins with a zero (0) |
| 5 | |
| 6 | function age($year, $month, $day, $time = null) { |
| 7 | if(!is_numeric($year) OR !is_numeric($month) OR !is_numeric($day)) { |
| 8 | return 'XX'; |
| 9 | |
| 10 | } else { |
| 11 | $diff = date_diff(date_create($year.'-'.$month.'-'.$day . (empty($time) ? null : ' '.$time)), date_create(date('Y-m-d'.(empty($time) ? null : ' Hi')))); |
| 12 | return $diff->y; |
| 13 | } |
| 14 | } |
| 15 | |
| 16 | ?> |