[英]How to create Excel formula to show how many hours have been between '-' separated time (“hh-hh”)
I have a simple OpenOffice Calc (Excel) ( .ods
) file that I use as a workers' timesheet. 我有一个简单的OpenOffice Calc(Excel)(.
.ods
)文件,用作工作人员的时间表。 It is written in the Finnish law, that I must have this list printed on my restaurant's wall for every 3 week period. 根据芬兰法律的规定,我必须每3周将这张清单印在我餐厅的墙上。 What I want is a formula that tells me how many hours is between some exact time written into cell (see example later).
我想要的是一个公式,该公式告诉我在写入单元格的确切时间之间有多少小时(请参阅后面的示例)。
Let's say that John Doe has marked to do 30.9.2014 shift from 14.00 to 02.00. 假设John Doe已将2014年9月30日的标记从14.00更改为02.00。 It is 12 hours and I now I have to input 14-02 to cell A1 and 12 to cell A2 (this strict type of input 14-02, nothing else).
现在是12个小时,我现在必须将14-02输入到单元格A1,将12输入到单元格A2(此严格类型的输入14-02,仅此而已)。
It would be much simpler to just write 14-02 and then A2 automatically would calculate, that how much have John Doe worked. 只需编写14-02,然后A2自动计算John Doe的工作量,就会简单得多。 The time input format must be "
hh-hh
" (HourHour-HourHour), hours only separated by a line "-". 时间输入格式必须为 “
hh-hh
”(HourHour-HourHour),小时仅由行“-”分隔。 As a restaurant we open typically 15.00 (15) and close just after midnight at 01.00 or 02.00 (01/02). 作为一家餐厅,我们通常营业时间为15.00(15),午夜刚过01:00或02.00(01/02)。 This could also be done by supermassive IF's and 24-15+(=IF(last two numbers and some weird formulas.
这也可以通过超大规模IF和24-15 +(= IF(最后两个数字和一些怪异的公式来完成。
I have tried to set cell settings manually, but to be honest, I have zero to none experience of how that works. 我尝试过手动设置单元格设置,但是老实说,我对它的工作原理有零到零的经验。 So, a formula that turns XX-XX to time format and calculates, how many hours is that.
因此,将XX-XX转换为时间格式并计算多少小时的公式。 If needed, I could put all possible combinations of time (11-17=6 ans so on) to somewhere bottom of my file (line 999 to be hidden).
如果需要,我可以将所有可能的时间组合(11-17 = 6 ans等等)放在文件底部的某处(要隐藏的第999行)。
The most simple solution would be to use Excel's DateTime format. 最简单的解决方案是使用Excel的DateTime格式。 With my local settings I would then input starting time in column A like
14:00
, ending time in column B like 02:00
- Excel will recognize the time format so when you do calculations in column C =B2-A2
the result will be in hour:minute format. 使用本地设置,我将在A列中输入开始时间,例如
14:00
,在B列中输入结束时间,例如02:00
-Excel将识别时间格式,因此当您在C列=B2-A2
进行计算时,结果将是以小时:分钟格式。
Since the ending time is after midnight you will have to take that into account by adding a day in your calculation in column C: =IF(B2<A2;B2+1-A2;B2-A2)
由于结束时间是午夜之后,因此您必须在C列的计算中添加一天来考虑该时间:
=IF(B2<A2;B2+1-A2;B2-A2)
If you can live with inputting the start and ending time in two separate columns instead of in the hh-hh
format you specify this will be the simples solution. 如果您可以在两个单独的栏中输入开始时间和结束时间,而不是使用
hh-hh
格式输入,则可以指定简单的解决方案。
Remember that if you input your hours in the format you specify you might have trouble with some local settings - if I for example try to enter that format in a cell Excel will think it is a date and convert it to such - to avoid that I must either format the column as text before entering any values or input it as '14-02
to make Excel see it as text 请记住,如果您以指定的格式输入小时数,则可能会遇到一些本地设置的麻烦-例如,如果我尝试在单元格中输入该格式,Excel会认为这是一个日期并将其转换为日期-以避免我必须在输入任何值之前将列格式化为文本,或将其输入为
'14-02
才能使Excel将其视为文本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.