indrayoga/bday
最新稳定版本:v0.1.0
Composer 安装命令:
composer require indrayoga/bday
包简介
PHP Package to calculate age, birthday and more
README 文档
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
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 3
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-01-13