Announcements

No record found.

Dynamics 365 general forum

# Calculate and populate school grade from date of birth

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.

• Community member 12 on at
Calculate and populate school grade from date of birth
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.
• Community Member Microsoft Employee on at
RE: Calculate and populate school grade from date of birth

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.

• LeoAlt 16,329 on at
RE: Calculate and populate school grade from date of birth

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.

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){
}
}
}

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

#### Dynamics 365 Community Update â€“ Sep 16th

Welcome to the next edition of the Community Platform Update. This is a weeklyâ€¦

#### Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the dailyâ€¦

#### Community Spotlight for September 2024

#1

AndrÃ© Arnaud de Cal... 290,349 Super User 2024 Season 2

#2

Martin DrÃ¡b 228,212 Most Valuable Professional

#3

nmaenpaa 101,148