Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Suggested answer

Calculate date difference into Month and Days

(0) ShareShare
ReportReport
Posted on by 1,227

Hi,

I would like to display 2 dates differences into month and days, e.g. 2 month 15 days. It seem standard calculated field is unable to achieve this, as the diffindays is calculate the total day in difference between the 2 dates.

In excel, we can use DATEDIF(A1,B1,"M") & "month ," &DATEDIF(A1,B1,"MD") & "days" it would return the desire result. How to achieve this ?

Thanks.

Regards,
Teh

  • Suggested answer
    Emily Zhang Profile Picture
    Emily Zhang on at
    RE: Calculate date difference into Month and Days

    I guess there's no oob function to achieve this. But you can write your own plugin.

    1. Register the plugin on record creation and update.

    2. Retrieve these 2 datetime attributes in plugin.

    3. Define 2 DateTime variable in the plugin, set datetime equals to attributes datetime.

    4. Compare month, days difference referring below document.

    docs.microsoft.com/.../system.datetime.month

    5. Pass the comparing difference back to CRM.

    But there's one issue with displaying 2 dates differences into month and days. For example: date1 is Jan 15th, date2 is March 3. If we compare date difference  into month and days, it will be come 2 month -12 days.

    If  you don't want negative number, then you need to make assumption, say every month is 30 days.

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

Announcing Our 2025 Season 1 Super Users!

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

Announcing Forum Attachment Improvements!

We're excited to announce that attachments for replies in forums and improved…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,979 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,848 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans