indrayoga / bday
PHP Package to calculate age, birthday and more
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/indrayoga/bday
Requires
- php: >=8.0
Requires (Dev)
- phpunit/phpunit: ^12.5
README
A simple PHP library to calculate age from birthdate with precise year, month, and day breakdown.
Installation
Install via Composer:
composer require indrayoga/bday
Usage
Basic Example
Calculate age from a birthdate:
<?php require 'vendor/autoload.php'; use Indrayoga\Bday\Bday; // Calculate current age $age = Bday::age('1990-05-15'); echo $age; // Output: 35 years, 8 months, 29 days // Access individual components echo $age->years(); // 35 echo $age->months(); // 8 echo $age->days(); // 29 // Get as array print_r($age->toArray()); // Array // ( // [years] => 35 // [months] => 8 // [days] => 29 // )
Calculate Age at Specific Date
Calculate age at a specific point in time:
<?php use Indrayoga\Bday\Bday; $age = Bday::age('1990-05-15', '2020-01-01'); echo $age; // Output: 29 years, 7 months, 17 days
Using DateTime Objects
You can also use DateTime objects instead of strings:
<?php use Indrayoga\Bday\Bday; $birthdate = new DateTime('1990-05-15'); $atDate = new DateTime('2020-01-01'); $age = Bday::age($birthdate, $atDate); echo $age->years(); // 29
Requirements
- PHP 8.0 or higher
License
MIT License