Forked from Padilo300/PHP вычислить возраст по дате рождения.
Created
February 28, 2022 12:53
-
-
Save dead23angel/6517611aecc9ec71547fd893228d6d80 to your computer and use it in GitHub Desktop.
PHP вычислить возраст по дате рождения.
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
function calculate_age($birthday) { | |
$birthday_timestamp = strtotime($birthday); | |
$age = date('Y') - date('Y', $birthday_timestamp); | |
if (date('md', $birthday_timestamp) > date('md')) { | |
$age--; | |
} | |
return $age; | |
} | |
//вызов функции | |
echo calculate_age('1990-01-01'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment