Calculate age RRS feed

  • Question

  • I want to calculate age in contact entity in crm 2011 , i have two fields birthdate and age field, i  m writing plugins  for this, i m not be able to get the proper solution so please help me.

    Thanks in advance



    • Edited by Raj Bind Friday, May 25, 2012 9:53 AM
    Friday, May 25, 2012 7:36 AM

All replies

  • Well you will need to subtract the birth date from the current date and then add some calculations

    var birth_date = Date.parse(myVar);
    var today_date = new Date();
    var diff_date =  user_date - today_date;
    var num_years = diff_date/31536000000;
    var num_months = (diff_date % 31536000000)/2628000000;
    var num_days = ((diff_date % 31536000000) % 2628000000)/86400000;

    Depending on how accurate you want the age, you can only use the values you need such as year.

    Please vote if you find my post useful. Add me on Skype @ christo.skype1

    Friday, May 25, 2012 2:01 PM