Trying to subtract two times. I have a time input box called Start Time and a time input box called End Time. Using a calculated field set to time =(EndTime-StartTime).TotalHours, I've tried .Hours as well. No matter how I write the calculation get the error "The expected type of this field is 'DateTime'"


I am a developer for Cognito Forms, I was able to reproduce this issue in our testing environment when the Calculation Type was set to 'Time'. In the settings for the Calculation Field try setting the Type to 'Number'. You are looking for a number value from the subtraction of the two times. You can continue to use either .Hours or .TotalHours.

enter image description here

  • Cognito Forms does have a duration, called TimeSpan, which is the type returned by the calculation (StartTime - EndTime). Time is a point in time on no specific day, like 3:00 PM, whereas TimeSpan represents a time interval, like 3 hours and 5 minutes. The issue in this case was the expected type of the calculation did not match the type returned by the expression. – Jamie Thomas Dec 5 '14 at 17:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.