Created
April 1, 2020 09:17
-
-
Save morgyface/b718daf485eeb68a6e89d6ca6a7f45d8 to your computer and use it in GitHub Desktop.
PHP | Age from date
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Return age in years from date of birth | |
| function get_age( $date_of_birth = 0 ) { | |
| $age = null; | |
| if( strtotime( $date_of_birth ) ) { | |
| $date_today = new DateTime('today'); | |
| $date_of_birth = new DateTime($date_of_birth); | |
| $age = $date_of_birth->diff($date_today)->y; | |
| } | |
| return $age; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment