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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics 365 | Integration, Dataverse...
Suggested Answer

Calculate and populate school grade from date of birth

(0) ShareShare
ReportReport
Posted on by 15

I can calculate a contact's age from their date of birth, but I would now like to calculate their school year.

In this country the new school year starts on April 2nd and the students' age on that date determines their school grade/year.

So firstly, I need to calculate their age on April 2nd of the current year.

I then need to link this to their school grade i.e. 'if age 13 on April 2nd of current year' automatically populates another field with 'Junior High School Grade 2'

Any help with formulas for Dynamics 365 would be appreciated.

I have the same question (0)
  • Suggested answer
    LeoAlt Profile Picture
    16,331 Moderator on at

    Hi partner,

    According to your description, I suggest you to use js function to do this beacuse it's very convenient and it can be flexible according to your needs.

    Here is the sample code for you.

    function getGrade(executionContext) {
        var today=new Date();
        var month = today.getMonth() + 1;//Get current Month
        var day = today.getDate();//Get current Day
        //If today is 04-02, then set the grade/year
        if(month==4&&day==2){
            var formContext = executionContext.getFormContext();
            var birth = formContext.getAttribute("new_Birthday").getValue();
            var birthDayTime = new Date(birth).getTime();
            var nowTime = new Date().getTime();
            var age = Math.ceil((nowTime - birthDayTime/ 31536000000);
            if(age==13){
                formContext.getAttribute("new_gradeyear").setValue("Junior High School Grade 2");
            }
        }
    }

    You said that you only want this function run at 04-02, but in D365 we could not specifies that the code is executed on a particular date, so I add this function in form onload event and if today is 04-02, it will trigger the function.

    Hope it helps.

    Best Regards,

    Leo

  • Community Member Profile Picture
    on at

    I agree with the authors above. I used the js function that was for my project. But the js function wasn't activated for a long time until I used an additional plugin for it. I got the manual from my programming teacher, who was implementing this project with me. I want to show him the code in the picture above. I think he'll approve and work on the implementation.

  • Community member Profile Picture
    12 on at
    brilliant solution! Converting birth dates to school grades is an innovative approach that simplifies academic records. But if you pay for essay at RoyalWriter.co.uk then it deserves praise. As a satisfied user, I appreciate their expertise and commitment to excellence. The seamless integration of technology and education is truly remarkable. Thank you RoyalWriter.co.uk for consistently providing quality services.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Microsoft Dynamics 365 | Integration, Dataverse, and general topics

#1
Pallavi Phade Profile Picture

Pallavi Phade 102 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 67

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 55 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans