Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

DIFFINDAYS ERROR

Posted on by Microsoft Employee

When using DIFFINDAYS for a calculated date time field, a user is trying to compare two custom date time fields.

DIFFINDAYS(New_Customdate, new_customdate2)

It returns the error " You Can't set the value DIFFINDAYS(New_Customdate, new_customdate2) Which is a type of integer to type DateTime.

Same error if you use DIFFINDAYS(New_Customdate, NOW())

Returns: It returns the error " You Can't set the value DIFFINDAYS(New_Customdate, NOW()) Which is a type of integer to type DateTime.

But the following works:

 DIFFINDAYS(createdon, NOW())

So that's a system field on the entity.   Why will this not work using two custom date fields or a custom date field with NOW()?

*This post is locked for comments

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: DIFFINDAYS ERROR

    Well, I finally got some sleep or rather I slept on why I was making a mistake. It came to me Friday.

    Early in 2015 , the first time I used the Diffindays was with the diffindays(createdon, NOW()) example and it worked.  The problem was that it got in my mind that this was comparing two date fields to get a numerical difference and the field I created was a Date field.  So that worked.  But I was wrong.  The error is not in the function.  It was me.  So here is the point.  I'm looking for a value or number, the difference between two date/time fields, but I was trying to put the results in a date time field the way, DIFFINDAYS(createdon, NOW()) shows the results in a date/time field.  But that's wrong.

    If you want a number ask for a number so the type whole number for a field allows for result to be stored.   With that everything works  

    Thanks for letting me bounce this off of everyone.

  • Suggested answer
    Hamzeh Zawahreh Profile Picture
    Hamzeh Zawahreh 3,674 on at
    RE: DIFFINDAYS ERROR

    dear cjspanburgh

     DIFFINDAYS will return an number value not a date.

    see this link:

    http://debajmecrm.com/2015/08/20/using-diffindays-to-auto-calculate-age-of-a-contact-dynamics-crm-2015-online-update-1/

  • Suggested answer
    Deeps Profile Picture
    Deeps 1,875 on at
    RE: DIFFINDAYS ERROR

    Hi

    The calculated field has to be of data type WholeNumber not DateTime. DIFFINDAYS will return an integer value not a date.

    I hope it clears.

  • MarkR_B Profile Picture
    MarkR_B 465 on at
    RE: DIFFINDAYS ERROR

    I would guess that there could be a format issue. Alert the attributes to screen and see if you can visually see the difference.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: DIFFENDAYS ERROR

    A reminder.  I am typing Diffindays in the formula.  Pardon the spelling error.

    /:>

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: DIFFENDAYS ERROR

     The same issue occurs with DIFFINWEEKS AND DIFFENMONTHS.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: DIFFENDAYS ERROR

    So createdon and Now() work fine.  That's the example in the MSDN site.

    I did that in the client online site and in the a new trial made two weeks ago.

    So I just tested again.

    In a new CRM 2015 online instance, I customized the account entity with two new date/time fields.

    new_deploymentdate and new_trainingdate.

    They are added to the form.

    Yes, it is published.  Changes are saved and published.

    Fields contain data.

    I created two date time fields.

    The types are date /time.

    Diffindays(new_deploymentdate, new_trainingdate)

    The calculated date/time field is set to the date/time.

    All are user local.

    Same error. 

  • P. R. M Profile Picture
    P. R. M 739 on at
    RE: DIFFENDAYS ERROR

    Hi,

    Can you please confirm CRM version (CRM 2015 or CRM 2015 update1)?

    Recently, I used "DiffInDays" function in calculated fields with custom date fields, Now() and CreatedOn. It was working fine without any errors. I did in CRM 2015 update1.

    Regards,

    Prasad Reddy Mamilla.

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: DIFFENDAYS ERROR

    I'll Check their Form Fields. Thanks.

  • Deeps Profile Picture
    Deeps 1,875 on at
    RE: DIFFENDAYS ERROR

    Are you sure data type for your custom fields is Date? Please check other properties of your custom fields also like is it Date only or Date Time etc? They should match when comparing with other date.

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Complete!

🔔 Be sure to subscribe to the new forums you are interested in to stay up to date! 🔔

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,902 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 229,316 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans