# Formula to work out end date & time - start date and time minus duration

Topic Labels: Formulas
426 6
cancel
Showing results for
Did you mean:  4 - Data Explorer

Help please! I want to create a formula that spits out the total amount of hours work less a break time for team time sheets. I’m using time and date field to record when people work and a duration field for breaks. Can anyone give me the formula to use please? 6 Replies 6  14 - Jupiter

The duration field holds its value in “seconds” under the hood. So a duration field displaying 1 hour (`1:00`) is actually holding the numerical value of `3600`.

So you could subtract your “Break” field from your “Hours” field, as hours, like this:

``````IF({Hours}, {Hours}, 0) - (IF({Break}, {Break} / 3600, 0))
``````  4 - Data Explorer

Thanks so much. Sadly this formula just spits out the same as the hours.   4 - Data Explorer

If someone works 8 hours and takes a 30 minute break, what is the formula to get 7.5 hours please?  14 - Jupiter

Is your `Billable Hours` field configured to display its value as an “Integer”? It needs to be configured to display as "Decimal, or else it is going to round `7.5` up to the nearest integer, which is `8`.  4 - Data Explorer

that’s it. Thank you!

Now my issue is that the hours column is not displaying half hour blocks. This should be 4.5 hours (instead of 4). Could you please tell me if this formula is right?    14 - Jupiter

What is the minimum increment you want to round to for your `Hours` field? If someone works 7 hours and 15 minutes, do you want it to record `7.25` hours? Or should that round up to `7.5` hours? And what are your rounding cutoffs? Should 8:00am - 1:45pm round up to 6 hours? Or down to 5.5 hours? What about 8:00am - 1:44pm?

If rounding is no issue (maybe you will just always enter “rounded” times like 2:00 instead of 1:45), then you can just change that formula to return its difference in minutes, and then divide by 60:

``````DATETIME_DIFF({Finish}, {Start}, "minutes") / 60
``````

That will get you fractions of an hour.

If rounding at thresholds is important, that will take a bit more work.

If you need to always round down until the next half-hour increment is met, `FLOOR()` should do the trick:

``````FLOOR(
DATETIME_DIFF({Finish}, {Start}, "minutes") / 60,
0.5
)
``````

FLOOR() rounding 7 hours and 59 minutes down to 7.5 hours worked If you want to round to the nearest half-hour, with 15-minute cutoff thresholds, this will do it:

``````IF(
MOD(DATETIME_DIFF({Finish}, {Start}, "minutes"), 60) >= 45,
CEILING(DATETIME_DIFF({Finish}, {Start}, "minutes") / 60, 0.5),
IF(
MOD(DATETIME_DIFF({Finish}, {Start}, "minutes"), 60) >= 30,
FLOOR(DATETIME_DIFF({Finish}, {Start}, "minutes") / 60, 0.5),
IF(
MOD(DATETIME_DIFF({Finish}, {Start}, "minutes"), 60) >= 15,
CEILING(DATETIME_DIFF({Finish}, {Start}, "minutes") / 60, 0.5),
FLOOR(DATETIME_DIFF({Finish}, {Start}, "minutes") / 60, 0.5)
)
)
)
``````

The formula above creates thresholds at the 15 minute marks for rounding up or down to the nearest half-hour     