-1

I have a form with two date fields and two time fields for a timesheet, and want to calculate the number of minutes between. If a job starts in the evening and ends in the morning, how can I calculate the number of minutes?

If the start and end are on the same day, my calculation works:

=(End - Start).TotalMinutes

but if it crosses midnight it returns a negative number.

0

I'm a developer with Cognito Forms.

This can be a bit complicated as you will have to tell the system what the date is for both the time fields, so they know that the time is on two different days. We do have an FAQ answer for a similar question.

https://www.cognitoforms.com/support/104/faq/how-can-i-calculate-total-hours-based-on-date-or-time-fields

We are calculating the total hours with the calculation, but you can adjust the calculation you can get the minutes. To do this you would still need the 4 Date/Time fields, but you would use the following calculation.

=(EndDate.AddMinutes(EndTime.Minute + (EndTime.Hour * 60)) - StartDate.AddMinutes(StartTime.Minute + (StartTime.Hour * 60))).TotalMinutes

We also have a template with all the fields set up, along with the working calculations to provide minutes, 15 minute blocks, and hours.

https://www.cognitoforms.com/templates/shared/DemoAccountForCognitoForms/TotalNumberOfHoursCalculation

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.