3

I am trying to make a validation rule for a Call Center that insures that when a call is manually entered, that it is not incorrect. I want a validation rule that checks that the call duration is less than 5 hours. The fields are in the DATETIME format like "11/1/2016 10:29 AM".

The validation rule should be something like what is below, but I keep getting errors with the format for the time difference of 5 hours.

Call_End_Time__c- Call_Start_Time__c < 5

What is the correct format to subtract two DATETIME fields to see if the difference is less than 5 hours, what the format for the <5 hours to read correctly?

2
  • 1
    What are your errors? Commented Nov 1, 2016 at 17:44
  • The difference is calculated in days, 5 hours would be ~ 0.20833
    – o-lexi
    Commented Nov 1, 2016 at 17:45

1 Answer 1

5

Since the difference is calculated in days, you must multiply the difference by 24 to get hours (or divide the threshold by 24). If you want to force the difference to be less than 5 hours, throw an error when the difference is greater than 5 hours.

24 * (Call_End_Time__c - Call_Start_Time__c) > 5

OR

Call_End_Time__c - Call_Start_Time__c > 5 / 24

While you could just check if the difference is less than 0.208333 (5/24), your formulas will be more readable if you avoid magic numbers. Note that if you want to compare the difference in minutes, you must divide/multiply by a further 60, and again for seconds.

5
  • Got me a bit further. Still for the Task object it does not like this validation rule for some reason. I can log a call that is: Call Start Time 10/10/2016 4:37 PM, Call End Time 10/11/2016 4:38 PM, Manual Duration 1.000694. The rule will pick up if it is 10/9/2016- 10/7/2016 for example that it is invalid but not when it should actually be invalid.
    – mburgSolar
    Commented Nov 1, 2016 at 23:39
  • The Validation Rule should use >, not <. My mistake. You want to throw an error when the duration is too great.
    – Adrian Larson
    Commented Nov 2, 2016 at 0:05
  • 1
    Thank you 'Call_End_Time__c - Call_Start_Time__c > 5 / 24' works! I guess my logic was the validation rules would validate that 'Insure that duration is less than .25' rather than validating that 'For this condition, throw an error if your duration is greater than .25' which are two different logics, I feel.
    – mburgSolar
    Commented Nov 2, 2016 at 17:23
  • @mburgSolar If this answer addressed your problem, please consider accepting it by clicking on the check mark/tick to the left of the answer, turning it green. This marks the question as resolved to your satisfaction, and awards reputation both to you and the person who answered. If you have >= 15 reputation points, you may also upvote the answer if you wish. There is no obligation to do either.
    – Adrian Larson
    Commented Nov 4, 2016 at 19:42
  • 1
    Thank you for letting me know! This is my first post, you have been vary helpful!
    – mburgSolar
    Commented Nov 15, 2016 at 22:11

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .