web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Calculating Age based on DOB

(0) ShareShare
ReportReport
Posted on by 190

Hi 

I created a Calculated field using Diffindays to calculate Age based on Today and dob field.

'DiffInDays(cat_dateofbirth, Now()) / 365'

 

The issue I have it does not take into consideration leap years. Is there anything I could add to the formula to make this work?

Or any code that does the job?

Thanks

 

 

*This post is locked for comments

I have the same question (0)
  • Dynamics365starsolutions.blogspot.com Profile Picture
    10 on at
    RE: Calculating Age based on DOB

    Hi Family ,

    Please Do Refer Blog of Mine

    I hope Your Question will be Answered

    dynamics365starsolutions.blogspot.com/.../age-using-javascript-in-d365-to-get-age.html

  • Kishore P Profile Picture
    45 on at
    RE: Calculating Age based on DOB

    Hi ,

    Try these:

    var DOB =Xrm.Page.getAttribute("DOB").getValue();
    var today = new Date();
    var birthDate = new Date(DOB);
    var age = today.getFullYear() - birthDate.getFullYear();
    var m = today.getMonth() - birthDate.getMonth();
    if (m < 0 || (m === 0 && today.getDate() < birthDate.getDate())) {
    age = age - 1;
    }
    Xrm.Page.getAttribute("new_Age").setValue(age);
  • Suggested answer
    Namrata11 Profile Picture
    77 on at
    RE: Calculating Age based on DOB

    You can use Date only field

    It is about Date of birth, we can consider as date only field

  • TomSmelser Profile Picture
    1,570 on at
    RE: Calculating Age based on DOB

    This worked for me. Thank you.

  • Bruna Teixeira Profile Picture
    5 on at
    RE: Calculating Age based on DOB

    Hi Namrata,

    I've taken a look at your suggestion and I think the problem is to create a new DOB field using User Local behavior. It could be a problem for users in different time zones as the date can change.

    I agree with the guys, I think there is no OOB way to solve this.

  • Suggested answer
    Namrata11 Profile Picture
    77 on at
    RE: Calculating Age based on DOB

    Hi,

    I have calculated age using OOB Calculated field.

    https://namratapani.wordpress.com/2019/03/20/oob-age-calculation-in-crm/ 

    Please check this once. Worked for me :)

  • Suggested answer
    Vipin J Profile Picture
    1,603 on at
    RE: Calculating Age based on DOB

    The business rule where seems to be not working ang giving an error - You can't use Now(), which is of type dateTime, with the current function.

    So i wrote a JavaScript to support my calculation of Age. Click Here

    vjcity.blogspot.com/.../how-to-calculate-age-in-dynamic-365-crm.html

  • Shane Brown Profile Picture
    190 on at
    RE: Calculating Age based on DOB

    Agreed doesn’t look like it is possible with OOB functionality.

  • Verified answer
    CSF90 Profile Picture
    on at
    RE: Calculating Age based on DOB

    This is the classic example of a solution that sounds like it should be simple but is actually really complex. You'll need a JavaScript function for it to be accurate - there is no way calculated fields or business rules will be able to work it out for you.

  • Suggested answer
    ashlega Profile Picture
    34,477 on at
    RE: Calculating Age based on DOB

    Hi Shane,

     why don't you use DiffinYears instead of DiffinDays?

     Or are you trying to get a decimal number for the age (as in 10.5, 40.73)?

     If that's the case, you might probably try:

    DiffinYears(cat_dateofbirth, NOW()) +DiffinDays(ADDYEARS(cat_dateofbirth, DiffinYears(cat_dateofbirth, NOW())), NOW()) / 365

     In other words, first get diff in years.. then add the portion of the year which is left after that

     There could still be a bit of difference, but it'would only be there if the last year was a leap year

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Aric Levin - MVP Profile Picture

Aric Levin - MVP 2 Moderator

#2
MA-04060624-0 Profile Picture

MA-04060624-0 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans