Feature Request #4694

Add Date::age_from_birthdate function

Added by Valeriy Volkov 4 months ago. Updated 4 months ago.

Status:New Start date:01/28/2013
Priority:Normal Due date:
Assignee:- % Done:

0%

Category:-
Target version:-
Resolution: Points:1

Description

It will be usefull to have this function in kohana

History

Updated by Josh Buckley 4 months ago

Wouldn't that essentially be DateTime::diff()? (http://php.net/manual/en/datetime.diff.php)

Updated by Jeremy Bush 4 months ago

I don't see a reason this should be added anyway. It seems awfully use-case specific.

Updated by Haralan Dobrev 4 months ago

If ever implemented here is the best birthday to age conversion I've seen:

// Given the birthday is in YYYY-MM-DD format
list($year, $month, $date) = explode('-', $birthday);

$age = (int) date('Y') - (int) $year;
$months = (int) date('m') - (int) $month;
$days = (int) date('d') - (int) $date;

if ( $months < 0 OR ($months === 0 AND $days < 0))
{
    $age--;
}

However I am against adding that to the core. But if someone comes here someday, this might help him to not look for such functionality from a framework.

Also available in: Atom PDF