Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Is there a way to calculate age from a Date of Birth field?

(0) ShareShare
ReportReport
Posted on by

I am currently using CRM 2013 and need to calculate age.  I only have DOB to go by.  I need to send an email when the contact is approaching a specific age.  Can this be done via workflow or business rule?

*This post is locked for comments

  • Suggested answer
    A Verma Profile Picture
    55 on at
    RE: Is there a way to calculate age from a Date of Birth field?

    You can also achieve this without writing any custom code via Power Automate (need to use an expression for calculating age). Please refer the below link:

    learningrefresh.home.blog/.../

  • stjohnt Profile Picture
    15 on at
    RE: Is there a way to calculate age from a Date of Birth field?

    Using your code, when saving my changes to the entity, the age field clears and on load the form always displays "unsaved changes." Do you know what could be causing these issues?

  • Namrata11 Profile Picture
    77 on at
    RE: Is there a way to calculate age from a Date of Birth field?

    Please find the steps-

    1) Calculate the Age using Calculated field

    2) Copy the Age to a whole number using Java Script (calculated field's onchange event.)

    3) Write a workflow on the change of Whole number field (Having Timeout when the condition will satisfy)

  • Suggested answer
    Vipin J Profile Picture
    1,603 on at
    RE: Is there a way to calculate age from a Date of Birth field?

    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

  • Verified answer
    Karuna Karan Profile Picture
    1,210 on at
    RE: Is there a way to calculate age from a Date of Birth field?

    JS to calculate Age of Contact

    1. Create custom field 'Age' in whole number format, and then put it in the form. Remember the schema name of this field + lock the field in form.

    2. Web Resource Type: Javascript

    function CalculateAge(birthday, ondate) {

     // if ondate is not specified consider today's date

     if (ondate == null) { ondate = new Date(); }

     // if the supplied date is before the birthday returns 0

     if (ondate < birthday) { return 0; }

     var age = ondate.getFullYear() - birthday.getFullYear();

     if (birthday.getMonth() > ondate.getMonth() || (birthday.getMonth() == ondate.getMonth() && birthday.getDate() > ondate.getDate())) { age--; }

     return age;

    }

    function birthdateOnChange() {

    // read the birthday value from the birthdate field

    var birthday = Xrm.Page.getAttribute("birthdate").getValue();

    // if the date contains a value calculate the age

    if (birthday != null) {

     // get the age

     var age = CalculateAge(birthday);

     // set the age to the new_age field

     Xrm.Page.getAttribute("new_age").setValue(age);

    }

    }

    Replace the 2 schema names in the code with yours.

    3. Add the Web Resource to Form Libraries, then to the Event Handlers and call function "birthdateOnChange"

    4. In the Form, double click the DOB field and in the event tab under Event Handlers, press add and then select library and call this function "birthdateOnChange".

    5. Save and publish the entity.

    6. Enter data or change data in DOB | if data already there then on form onload you will see the correct Age!

  • Verified answer
    Iswarya Profile Picture
    1,347 on at
    RE: Is there a way to calculate age from a Date of Birth field?

    Hi Ben,

    you can calculate age by using javascript, i achieved this scenario in ms crm 2016 below my code

    function AgeCategory() {
    var age = 0;
    var Now = new Date(); //Todays Date
    var Birthday = Xrm.Page.getAttribute("new_Dateofbirth").getValue();

    //Get the Date of Birth value
    if (Birthday != null) {
    var diff = Now.getMonth() - Birthday.getMonth(); //Check to see if Birthday has already passed
    if (diff > -1) //If Birthday has already occurred
    {
    var bd1 = Now.getFullYear() - Birthday.getFullYear();
    age = bd1.toString();

    }
    else //If Birthday has not already occurred
    {
    var bd2 = Now.getFullYear() - Birthday.getFullYear() - 1;
    age = bd2.toString();

    }
    }
    }

  • Verified answer
    Kumar Viju Profile Picture
    1,026 on at
    RE: Is there a way to calculate age from a Date of Birth field?

    Hi,

    You need to write Custom Code to meet your requirement. 

    https://community.dynamics.com/crm/f/117/p/214885/570073#570073 

  • Verified answer
    Tim Dutcher Profile Picture
    2,100 on at
    RE: Is there a way to calculate age from a Date of Birth field?

    Search the forum for the following: birthday email send

    You'll find lots of responses/tips on this.

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

Jainam Kothari – Community Spotlight

We are honored to recognize Jainam Kothari as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >

Featured topics

Product updates

Dynamics 365 release plans