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.
I am a developer for Cognito Forms.
Since February 2015 the following functionality has been made available:
In this example, I am setting the range on the Start Date field to =DateTime.Today
. It could have also been =DateTime.Today.AddDays(1)
to be tomorrow or later. Calculations are very robust and should cover most scenarios you can dream up, but you can also just enter literal dates.
I then set the range on the End Date to be at least three days after the Start Date, but no more than seven days. Here is the calculation for the End Date minimum:
And this is how the Start Date appears on the form, with the days before today disabled:
And similarly for the End Date, with both minimum and maximum date restrictions based on the Start Date.
The date range for the End Date automatically updates based on changes to the Start Date, so if an End Date is specified and the Start Date is later changed, validation will catch this if the user does not fix it first.
Please note that range validation applies to Date, Number and Currency fields, not just the dates included in this example.
Best Answer
I'm a developer with Cognito Forms.
Your very very close with the calculation you currently have. You just need to add a day to your calculation so that a start date of 9/8/16 and an end date of 9/8/16 will give you one day, this will work for the rest of your entered dates as well.
A start date of 9/8/2016 and an end date of 9/10/2016 will give you 3 days. You can check out the updated calculation below and a link to a demo template.
https://www.cognitoforms.com/templates/shared/CognitoFormsTestAccount/LeaveRequestDemo