You are here

function _birthdays_calculate_age in Birthdays 6

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

Calculate age

Return value

int age

2 calls to _birthdays_calculate_age()
BirthdaysTestCase::testHideYearOption in ./birthdays.test
Test the year of birth visibility options.
_birthdays_get_age in ./birthdays.module
Get age from a given date of birth

File

./birthdays.module, line 968
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;
  }
}