简体   繁体   中英

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. It is written in the Finnish law, that I must have this list printed on my restaurant's wall for every 3 week period. 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. 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).

It would be much simpler to just write 14-02 and then A2 automatically would calculate, that how much have John Doe worked. The time input format must be " hh-hh " (HourHour-HourHour), hours only separated by a line "-". As a restaurant we open typically 15.00 (15) and close just after midnight at 01.00 or 02.00 (01/02). This could also be done by supermassive IF's and 24-15+(=IF(last two numbers and some weird formulas.

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. 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).

The most simple solution would be to use Excel's DateTime format. 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.

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)

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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