You are here

function _birthdays_calculate_age in Birthdays 5

Same name and namespace in other branches
  1. 6 birthdays.module \_birthdays_calculate_age()

Calculate age

Return value

int age

1 call to _birthdays_calculate_age()
_birthdays_get_age in ./birthdays.module
Get age from a given date of birth

File

./birthdays.module, line 1424
The Birthdays module allows users to add their birthday to their profile. It lists birthdays on a seperate page and in different blocks. Users can receive an e-mail on their birthday automatically, and the administrator can receive daily reminders of…

Code

function _birthdays_calculate_age($day, $month, $year) {
  if ($year && $month && $day) {

    // age = (current year - birthyear) - 1 (when the birthday hasn't arrived yet).
    return format_date(time(), 'custom', 'Y') - $year - (format_date(time(), 'custom', 'nd') < $month . str_pad($day, 2, 0, STR_PAD_LEFT));
  }
  else {
    return NULL;
  }
}