It seems that the value in cell Q4 is a DateTime. In Excel, this is stored as a number where the integer part is the number of days and the fractional part is the time of day. To get the number of hours instead of the number of days you need to multiply by 24. The following formula will get you the number of hours in excess of 40.
=IF(Q4*24>40,Q4*24-40,0)
If Q4 contains 49:23, this formula returns 9.3833. Make sure that the cell containing the hours of overtime is formatted as a number (or "General") rather than a time.
If you want to ignore fractions of an hour, use the INT
function:
=IF(Q4*24>40,INT(Q4*24-40),0)
As Scott points out in his comment (thanks Scott), repeating the Q4*24-40
in the formula is inelegant and can lead to errors if the formula needs to be changed. A better version of the first formula would be:
=MAX(Q4*24-40,0)
and a better version of the second would be:
=MAX(INT(Q4*24-40),0)
These work because any time Q4*24
is less than 40
, Q4*24-10
will be less than zero and the MAX
function will then return 0 instead of Q4*24-40
.