Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics 365 | Integration, Dataverse...
Answered

Add +1 to the DateDiff result formula

Posted on by 873

Hello,

I have two date fields start and end date in a form. I would like to calculate the difference between those dates which can be achieved using the below formula:

DIFFINDAYS(cr1b0_startdate, cr1b0_enddate)

Example: Start Date: 5/11/2022 - End Date: 5/23/2022
Total: 12 Days

According to the above formula, the result is 12 days, however, in our requirements, we need to add and wrap the formula with a +1 as a result because the real total should be 13 days.
aDDdAYFormula.png

What should be the updated formula to add +1 to DIFFINDAYS(cr1b0_startdate, cr1b0_enddate)?

Could you please provide an example to achieve the above requirements?

Any help is highly appreciated.

Best regards,
EBMRay

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Add +1 to the DateDiff result formula

    Hi EBMRay,

    Calculated field can't do this. You should use JS.

  • EBMRay Profile Picture
    EBMRay 873 on at
    RE: Add +1 to the DateDiff result formula

    Hi ,

    Thank you so much for providing the above example, it worked perfectly.

    Will it be possible to exclude weekends and public holidays through the calculated fields or this is something that should be done in JS?

    Awaiting your response.

  • Verified answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Add +1 to the DateDiff result formula

    Hi EBMRay,

    DIFFINDAYS() need two date and time value as parameter and return type is whole number. ADDDAYS() first parameter is whole number type, second is date and time type and return type is date and time.

    The reason you get this error is because you pass two whole number as parameter to ADDDAYS(). So you can first add 1 day to end date and then use DIFFINDAYS().

    Please try this expression:

    DiffInDays(cr884_startdate, AddDays(1, cr884_enddate))

    Test:

    pastedimage1653370820184v1.png

    Result:

    pastedimage1653370844298v2.png

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans