Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/full-stack-web-developer-and-designer/php-function-for-determine-age
PHP function to determine a person's age.
https://github.com/full-stack-web-developer-and-designer/php-function-for-determine-age
mirnesglamocic php phpfunction
Last synced: 7 days ago
JSON representation
PHP function to determine a person's age.
- Host: GitHub
- URL: https://github.com/full-stack-web-developer-and-designer/php-function-for-determine-age
- Owner: Full-Stack-Web-Developer-and-Designer
- License: mit
- Created: 2023-01-28T01:26:07.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-01-29T17:47:02.000Z (almost 2 years ago)
- Last Synced: 2023-10-31T04:30:41.984Z (about 1 year ago)
- Topics: mirnesglamocic, php, phpfunction
- Language: PHP
- Homepage: https://PHP-copyright.mirnesglamocic.repl.co
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP-function-for-determine-age
For working with people data, there are two ways to store age, that is as an integer or as a date of birth. The latter is generally preferred because it does not require anyone to manually update that information.Therefore, this repository contains a PHP class with properties where is defined the `get_age()` function. Then, is converted the person's date of birth in the format **YYYY-MM-DD** to an age in years.
PHP has a very helpful build-in function the **DateTime class** that help us convert a date of virtually any format into something we can use for conversions. So, in this case with function `get_age()` it's converted a date of birth to a new DateTime class and inside it is sent the date of birth that is a property of the object. Then, with function **Date** it's get today's date.
Finally, with function `diff` is substracted date of birth from today's date. With the PHP year property, only the age number of the specified person from the Person class is returned.
---
To check how it looks, click on the preview and then on the green run button.
##
[PREVIEW](https://replit.com/@MirnesGlamocic/PHP-function-for-determine-age?v=1)