Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Datediff in calculated fields is incorrectly calculating

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

I am using the datediff function in the calculated fields to calculate how long a case has been open for. I am using a whole number datatype with duration format (I have also tried none format). The formula I have used is  DiffInYears(createdon, Now()), but I have also tried months and hours for the datediff formula.

The result is completely off and inconsistent. For example a case that was created two months ago may show a duration of 11 hours while another one will show a duration of two minutes even though it is days old. Also, the Years option and Hours option in the datediff calculation will show two separate results, it will 2 minutes and 11 hours for the same case (the result in the field shows hours and minutes next to the field).

I suspect is trying a conversion of some sort from the UTC field.

I would much appreciate anyone's advice or assistance on this. Thank you.

*This post is locked for comments

  • Suggested answer
    Michael Mayo Profile Picture
    Michael Mayo 2 on at
    RE: Datediff in calculated fields is incorrectly calculating

    MS CRM is on to something, but missing this very important detail: The field needs to be deleted and recreated with the format NOT set to "duration" but rather "none"

  • Suggested answer
    Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Datediff in calculated fields is incorrectly calculating

    @Lindsay61,

    If you assign a value returned by statement "DiffInYears(createdon, Now())", you will always get the difference value in terms of MINUTES, as the Duration type of Field's lowest denomination is MINUTES. It accepts value in Minutes and then converts it into HOURS and DAYS andso on.

    Hence, you need to convert the Calculated formula as:

    DiffInMinutes(createdon, Now()),

    And assigned the return value to the Field.

    I hope this helps.

  • Nadeeja Bomiriya Profile Picture
    Nadeeja Bomiriya 6,804 on at
    RE: Datediff in calculated fields is incorrectly calculating

    Hi Lindsay61,

    Can you please include a screenshot of the calculated field configuration?  Also, what's the data type of the calculated field?

  • Suggested answer
    Nithya Gopinath Profile Picture
    Nithya Gopinath 17,076 on at
    RE: Datediff in calculated fields is incorrectly calculating

    Hi Lindsay,

    Please go through the following blog.

    community.dynamics.com/.../new-calculated-field-functions-in-crmonline-update-1

    It says, the trick to getting UTC time, in this case, is to first create the date time field as User Local, fill in the calculation field action, and only then change the date time behaviour to Time Zone Independent. Also note that, it is possible to change the date time behavior from User Local to Time Zone Independent, but not the other way around (from the UI).

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…

Vahid Ghafarpour – Community Spotlight

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

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,853 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans