| 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 | ?> |
airikr / Calculate age
Last active 4 months ago
Calculate the age of someone or something.
Revision c9ce308f98415ae10fdc5cb843f81dc95802e73e