Customization for age

Discussion in 'Customization & add-ons' started by medix, Jan 25, 2009.

  1. medix

    medix New Member

    Joined:
    Dec 17, 2008
    Messages:
    9
    Hi,

    i was wondering if any of you has idea about how to include age in the profile as a dynamic value, i mean that is calculated automatically by aMember based on the birthdate entered by the member so it gets updated every year as well. Im researching myself and trying to find a solution for this.

    thank you.
  2. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    Code:
    date_default_timezone_set('America/Los_Angeles');
    
    function calculateAge($birthday){
       
        return floor((time() - strtotime($birthday))/31556926);
       
    }
    
    //USAGE EXAMPLES
    
    echo calculateAge('1978-07-11');
    
    echo calculateAge('7/11/1978');
    
    echo calculateAge('7/11/78');
    
    echo calculateAge('July 11, 1978');
  3. medix

    medix New Member

    Joined:
    Dec 17, 2008
    Messages:
    9
    Hi,

    thank you. Where should i put the function? i want the age displayed in the ACP in the members edit page. Also. i guess its okay to change the dates for variables, since this values will change according to the user that is displayed.

    Thanks.
  4. skippybosco

    skippybosco CGI-Central Partner Staff Member

    Joined:
    Aug 22, 2006
    Messages:
    2,526
    Are you using add-on fields on the signup page to have the users enter their birthday information?
  5. medix

    medix New Member

    Joined:
    Dec 17, 2008
    Messages:
    9
    Yes, i have a 3-dropdown-box set where the user enter their date of birth. I created custom field for Year, month and day each. Now i would like to have an additional field for the age, but not entered by the member but calculated automatically by aMember and updated every year on their birthday. I asked aMember staff about this possibility but they say it requires customization and right now they have a long task list so im trying to figure it out myself.

    thanks.

Share This Page