Subtracting Hours in Query

rastus

Board Regular
Joined
Jul 8, 2005
Messages
157
Hi

I have a query with two calculated fields that return the business hours between two sets of dates in the format "h:nn".

What I would like to do is subtract the first field [HoursA] from the second [HoursB], but the expression [HoursA] - [HoursB] doesn't work like it would in excel. I have also tried DateDiff("n", [HoursA], [HoursB]), but this only works if either field is less than 24 hours.

Does anyone have a expression for subtracting these calculated fields e.g. 20:00 - 5:00 = 15:00 hours?

Regards
R
 

Some videos you may like

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.

Leandroarb

Board Regular
Joined
Oct 7, 2014
Messages
157
Hi Steve, How are you? I did a test here that just as you quoted, calculated fields in the query subtracting one hour from another, on principle did not work, as if the values ​​were divided by one hundred, to solve I put the format of the fields in the query as "h: nn", you tried it?
 

xenou

MrExcel MVP
Joined
Mar 2, 2007
Messages
16,792
Office Version
  1. 2019
Platform
  1. Windows
If your fields are true dates you should be able to add/subtract directly. Is the result of your query a true time in time format, or is it a text string that represents a time? When you say it doesn't work, what is the error or problem you are getting?
 

Watch MrExcel Video

Forum statistics

Threads
1,122,370
Messages
5,595,764
Members
414,017
Latest member
surajks

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
Top