简体   繁体   English

如何在 Excel 公式中减去固定时间?

[英]How to subtract fix hours in an Excel formula?

I've been looking on the inte.net and here on the site, but I don't find an example: I would like to calculate the difference between two hours, but if one is in the morning (smaller than 12:00) and the other in the afternoon (larger than 13:00), an hour should be subtracted.我一直在 inte.net 和网站上寻找,但我没有找到一个例子:我想计算两个小时之间的差异,但如果一个是在早上(小于 12:00)另一个在下午(大于13:00),应减去一个小时。

As the values "08:00", "16:00" and "17:00" are accepted by Excel, I thought this would be easy, something like:由于值“08:00”、“16:00”和“17:00”被 Excel 接受,我认为这很容易,例如:

=IF(AND(B3<=12:00,C3>=13:00),C3-B3-1,C3-B3)

But the values "12:00" and "13:00" are not recognised by Excel. How can I write my formula (as readable as possible, please, calculating 13/24 and using this constant in my formula is not very readable:-) ).但是值“12:00”和“13:00”不被 Excel 识别。我如何编写我的公式(请尽可能可读,计算 13/24 并在我的公式中使用这个常量不是很可读: -))。

I've opted for this solution:我选择了这个解决方案:

=IF(AND(B3<=TIME(12,0,0),C3>=TIME(13,0,0)),C3-B3-TIME(1,0,0),C3-B3)

This says precisely what I want: in case I started in the morning ( B3<=TIME(12,0,0) ) and ended in the afternoon ( C3>=TIME(13,0,0) ), then I subtract one hour TIME(1,0,0) from the difference (taking lunchtime into account).这正是我想要的:如果我早上开始( B3<=TIME(12,0,0) )并在下午结束( C3>=TIME(13,0,0) ),那么我减去一个小时TIME(1,0,0)的差异(考虑午餐时间)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM