Using 24 hour calculations in numbers over different days

Hi - I'm new to Numbers. I'm trying to create a simple spreadsheet using basic time calculations, utilising the 24 hour clock. Most of the time it is working however when times cross over days there is an error in how I am trying to get the calcualtion to work.


For example, the total time elapsed from (starting) 2300 to 0225 (finishing) is 3 hrs 25 mins. (Obviously, 11 pm till 2:25 am the next morning....). I need to subtract the finishing time from the starting time. Numbers produces an answer of -20:35. I understand how and why, but I it's not what I want. Usually entering fields such as starting at 0800 and finishing at 1300 works fine for simple reasons. I also know to enter the times as "23:00" and "03:25", but do I have to do that??


Any solutions please?

MacBook Pro, iOS 6.1.2

Posted on Mar 15, 2013 8:34 PM

Reply
4 replies

Mar 15, 2013 11:00 PM in response to PHendo777

The issue you're running into is that apple has adopted ISO standards for recording Date and Time values. Any time your see displayed in Numbers is a Date and Time value, with only the Time part displayed. Any Date you see displayed in Numbers is a Date and Time value, with only the Date part displayed. No matter which part is displayed, a reference to the cell will always return the full Date and Time value.


When you enter a Date, Numbers automatically sets the Time part of the value to 00:00:00 (midnight, at the beginning of that date).


When you enter a Time (of day), Numbers automatically creates a full Date and Time value by setting the date part to 'today's date'. (This is the setting that affects your calculations.)


The base unit for Date and Time value is the day, so there are ways to correct for this apparent error.


Here is your basic formula for calculating the Duration between two Date and Time values where B2 contains the Start time, C2 contains the Finish time, and both are on the same calendar day:


=C2-B2


The result will be a Duration value


To avoid having to correct for a start time before midnight and a finish time after midnight, the straightforward solution is to enter those times during the calendar day on which each occurs. That's straightforward, but not always convenient.


If both times are entered on the same calendar day, you can apply a correction factor to the formula above:


=IF(C2<B2,C2+1-B2,C2-B2)


The result will be a positive Duration value.


Taking it one step further, you can use TIMEVALUE to strip the Date part from a Date and Time value, leaving a decimal fraction representing the portion of the day that has passed.


=IF(C2<B2,1+(TIMEVALUE(C2)-TIMEVALUE(B2),TIMEVALUE(C2)-TIMEVALUE(B2))*24


The result is a number representing the number of hours between the two times.


Here's a table showing five examples, and the results of the formulas above:

User uploaded file


Regarding: "I also know to enter the times as "23:00" and "03:25", but do I have to do that??"


Yes. Numbers will not recognize a (date and) time entry without the colon.


Regards,

Barry

Mar 15, 2013 11:35 PM in response to Barry

Thanks.... I've been using the basic C2-B2 forumla but the others you've provided will help a lot. (I thought I found a fix of changing the field to include a DAY:HOUR:MINUTE and not just HOUR:MINUTE but I have to do that only for the fields that require it = annoying!)


I tried the formula =IF(C2<B2,C2+1-B2,C2-B2)however I'm getting a negative answer still. In my example the start time is 2359 (B2) and finish time is 0518 (C2) the next day, then I'm getting "-18" as a result.

Mar 16, 2013 1:49 AM in response to PHendo777

Not sure how your managing to get that result.


If you've entered only the Time part of a Date and Time value on both cells, the example should work as row 2 below. values entered were B2: 23:59, C2: 05:18. Cell format was set to Automatic, so the date part was appended (using March 16, the date the value was entered in each cell), but was not displayed. You can see the full value displayed in the editing box above the table.


In row 4, the full Date and Time value shown was entered in B4, only the time part was entered in C4 (then the cell was formatted to show both parts).


The formula was copied from your post above, pasted into D2, filled down to D4, then deleted from D3 (where it was displaying a zero—as it should in that row).

User uploaded file


Entered without the colon, 1159 in B2 and 0518 in C2 are numbers, not times. Numbers drops the leading zero from the second number, and gives the correct result -640 (518 +1 - 1159 = -640).


There's no need to change the 'field" (cell?). If you enter a time in one of the accepted formats, Numbers will recognize it, complete the Date and Time value but appending the date of entry before the time part, and set the cell to display only the part that was entered. See the selected cell above.


How did you "change the field"?


Regards,

Barry

Mar 16, 2013 2:58 AM in response to Barry

I changed the cell format units from HR:MIN to DAY:HR:MIN so I'd enter the day number before the time, eg 23:23:59 then in the next cell 24:05:18. That seemed to work, but a pain to do so of course. I kept the cell format as DURATION. Since changing it to AUTOMATIC as you suggested the formula you kindly gave me is working, as I've done with all the cells now.


Then and now I'm trying to conditionally format the cells. I just want to allow a negative value ("LESS THAN" value 0) to be filled green, and a positive value ("GREATER THAN" value 0) as red. It won't show the fill as anything, ie no change. However, if I try to change the field to "NOT EQUAL TO" value 0) it will give me a filled colour. But then, even if I select all the cells column I wish to apply this to, they all go green, even those where the result between sets of data is "0:00".


Thanks for your patience and help!!!


User uploaded file

User uploaded file

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Using 24 hour calculations in numbers over different days

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.