How to Calculate Number of Days Between Two Date and Time Fields

Tips 300x225 How to Calculate Number of Days Between Two Date and Time Fields

In today’s blog, we are going to demonstrate how to calculate the difference in the number of days between two date and time fields. This functionality also works for the Date & Time and Date Only field as well as the Date Only and Date Only fields. Which means that you can use any possible combination of custom or out-of-the-box Date fields.

In the scenario below, we will estimate the number of days it took the Sales Rep to qualify a Lead to an Account.

Lead Creation Date

First, we will create a Lead Created On field that will hold the information we already possess on the Lead record. In the scenario below, we are using the Date & Time field, as the Created On field on the Lead record is the same format.

021218 1639 HowtoCalcul1 How to Calculate Number of Days Between Two Date and Time Fields

 Calculated Field

The next thing we have to do is to create a Calculated field type Decimal Number. The reason we have selected Decimal Number is because we are using two Date & Time fields as Dynamics 365 includes the Created on Time as part of the calculation. However, we are interested only on the number of days so we will set the Precision value to zero (0). You also can use a Whole Number field type based on your project requirements.

021218 1639 HowtoCalcul2 How to Calculate Number of Days Between Two Date and Time Fields

Calculation Logic

Once you have saved the field, click on edit and set up the logic. In this scenario, we will use the DiffinDays function and specify the start and end date and time. Although, when using the DiffinDays function within the brackets it specifies Date & Time field, the functionality equally works if you select Date Only field type.

021218 1639 HowtoCalcul3 How to Calculate Number of Days Between Two Date and Time Fields

In Action

After saving and publishing the changes, we can go back to the form and test the new function.

021218 1639 HowtoCalcul4 How to Calculate Number of Days Between Two Date and Time Fields

There you have it! For more tips and tricks for using Microsoft Dynamics 365, keep checking our blog!

Happy Dynamics 365’ing!

Let’s block ads! (Why?)

PowerObjects- Bringing Focus to Dynamics CRM