Personalized Community is here!
Quickly customize your community to find the content you seek.
Check out the latest Sales updates!Learn about the key capabilities and features of Dynamics 365 Sales and experience some of the new features.
Download overview guide | Watch Sales video
2021 Release Wave 2Discover the latest updates and new features releasing from October 2021 through March 2022.
2021 release wave 2 plan
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Community | FastTrack Program | Finance and Operations TechTalks | Customer Engagement TechTalks | Upcoming TechTalks | All TechTalks
I am looking for a way to calculate the difference between a start date and our year-end date. Has anyone come across a requirement and a solution to calculate the difference between a date and the companies year-end? I was thinking of using a hidden field that would set the year-end on the creation of a record, but this approach would require a batch job to ensure the year-end date is correct.
I'm not clear about your question.
Do you have two date fields in your entity, start date and year-end date? And you want to count the days from start date to year-end date?
Could you give some sample date and your expect output?
Using C# code.
You can use the below code to find difference between two dates.
• Difference in Days.
int numOfPassedInvoices = (endDate - startDate).TotalDays;
• Difference in Weeks
(Use Math.Truncate only if you do not consider the current period and if you want to consider the current period use Math.Ceiling)
int numOfPassedInvoices = Convert.ToInt32(Math.Truncate((endDate - startDate).TotalDays / 7));
• Difference in Months
int numOfPassedInvoices = Convert.ToInt32(Math.Truncate((endDate - startDate).TotalDays / 30.4));
• Difference in Years
int numOfPassedInvoices = Convert.ToInt32(Math.Truncate((endDate - startDate).TotalDays / 365));
The below code is to find the year difference.
var startDate = new Date();var endDate = new Date("01/01/2023");var diffDays = Math.ceil( parseFloat((endDate - startDate) / (1000 * 60 * 60 * 24 * 365), 10));
To find difference in days remove the 365.To find difference in weeks replace the 365 with 7.To find difference in Months replace the 365 with 30.4.
However if you do not have the constant end date value and you have different companies records with different year end, in that case you need to have a separate field to store the End Date.Now to find the difference you can create a Calculated DateTime fields as shown below.
The calculated field will provide multiple type of function to find difference in Days, Weeks, Months and Years etc.
Hope this helps.
Business Applications communities