Subtract hour from time

30percent

Board Regular
Joined
May 5, 2011
Messages
123
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I tried to subtract 5 hours from a certain time with the following formula: =A1-(5/24). However, time that are after 24:00 resulted in #######.
Could someone please explain why that happened and how should I change the formula? Thanks

TimeAfter Subtract
23:0018:00
0:30##########
1:00##########
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Excel won't represent negative times. If a calculation results in a negative time, the cell will be filled with "#".

This formula will work for you. If the first time is earlier than 5:00 AM you have to add 1 to make it a day later, then subtract the 5 hours.

Excel Formula:
=IF(A1<5/24,1,0)+A1-5/24
 
Upvote 0
This is how Microsoft says the MOD function is evaluated:
n - d*INT(n/d)

SInce the denominator is 1, we can basically take that out because multiplying by 1 and dividing by 1 doesn't change anything.

so this reduces to n-int( n )
So if A1 is 1:30, then subtracting 5 hours shown as a decimal is -.1458333333

if you apply the INT function to this number, it will become -1

so

-.1458333333 - -1

becomes

-.1458333333 + 1 which is .854167

which when formatted as time is 20:30
 
Upvote 1
shown as a decimal is -.1458333333

if you apply the INT function to this number, it will become -1
That's the surprise to me. I thought INT simply truncated the decimal portion and would give 0 in this case. But I've never used it with negative numbers. I see that the spec says "Rounds a number down to the nearest integer." To me that's odd behavior for negative numbers, but it is what it is.
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top