airikr revidoval tento gist 2 years ago. Přejít na revizi
1 file changed, 11 insertions, 3 deletions
age.php
| @@ -1,8 +1,16 @@ | |||
| 1 | 1 | <?php | |
| 2 | 2 | ||
| 3 | - | function age($year, $month, $day) { | |
| 4 | - | $diff = date_diff(date_create($year.'-'.$month.'-'.$day), date_create(date('Y-m-d'))); | |
| 5 | - | return $diff->y; | |
| 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 | + | } | |
| 6 | 14 | } | |
| 7 | 15 | ||
| 8 | 16 | ?> | |
airikr revidoval tento gist 2 years ago. Přejít na revizi
1 file changed, 8 insertions
age.php(vytvořil soubor)
| @@ -0,0 +1,8 @@ | |||
| 1 | + | <?php | |
| 2 | + | ||
| 3 | + | function age($year, $month, $day) { | |
| 4 | + | $diff = date_diff(date_create($year.'-'.$month.'-'.$day), date_create(date('Y-m-d'))); | |
| 5 | + | return $diff->y; | |
| 6 | + | } | |
| 7 | + | ||
| 8 | + | ?> | |