Feature Request #4694

Add Date::age_from_birthdate function

Added by Valeriy Volkov almost 2 years ago. Updated almost 2 years ago.

Status:NewStart date:01/28/2013
Priority:NormalDue date:
Assignee:-% Done:

0%

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

Description

It will be usefull to have this function in kohana

History

#1 Updated by Josh Buckley almost 2 years ago

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

#2 Updated by Jeremy Bush almost 2 years ago

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

#3 Updated by Haralan Dobrev almost 2 years 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