locked
How to compute age on Onsave? RRS feed

  • Question

  • Hello to all.....

    i have a field birth date.... I want to get their age...

    var regdate=crmForm .all .Birthdate.DataValue;

    var birthdate = regdate - nowdate;

    if(birthdate == 19)
    {
    ......
    }

    Thank you....

    Zosimo D. Recio Jr. Microsoft Certified (Business Management Solutions specialist)
    Wednesday, July 1, 2009 3:21 AM

Answers

  • Hi,


    if(crmForm.all.birthdate.DataValue!=null)
    {
    var birthday=crmForm.all.birthdate.DataValue;

     if ((birthday.getYear() != 0) || (birthday.getYear() < 99))

    {
     var now = new Date();

    var ms = now.valueOf() - birthday.valueOf();

    var minutes = ms / 1000 / 60;
    var hours = minutes / 60;
    var days = hours / 24;
    var years = days/365;

    var age=years.toString();

    var age1=age.substr(0,2);

    var finalage=age1-0;

    alert("finalage");
    crmForm.all.age.DataValue=finalage;
    }
    }
    Thanks, Aarch
    Wednesday, July 1, 2009 5:30 AM

All replies

  •     var todaysDate = new Date();
        var birthday = crmForm.all.birthdate.DataValue;
        var age = todaysDate.getYear() - birthday.getYear();
        if(age == 19)
        {
         // do some stuff here
        }
    
    havn't tested it.
    http://mscrmblog.net
    Microsoft Certified Business Management Solutions Specialist
    Microsoft Certified CRM Developer
    Wednesday, July 1, 2009 5:24 AM
  • Hi,


    if(crmForm.all.birthdate.DataValue!=null)
    {
    var birthday=crmForm.all.birthdate.DataValue;

     if ((birthday.getYear() != 0) || (birthday.getYear() < 99))

    {
     var now = new Date();

    var ms = now.valueOf() - birthday.valueOf();

    var minutes = ms / 1000 / 60;
    var hours = minutes / 60;
    var days = hours / 24;
    var years = days/365;

    var age=years.toString();

    var age1=age.substr(0,2);

    var finalage=age1-0;

    alert("finalage");
    crmForm.all.age.DataValue=finalage;
    }
    }
    Thanks, Aarch
    Wednesday, July 1, 2009 5:30 AM