I am flabbergasted as to what I am doing wrong as I simply want it to show 39:54 (39 hours, 54 minutes). I'm guessing it's something obvious but the formulas I've tried either give me 21:36 (?) or 39.9. 39.9 makes sense as it's 39 hours but the .9 is related to 54 minutes being 90% of 60 minutes.
Any help is much appreciated. Thank you !
You are doing it wrong.
=TEXT(M3-L3,"[hh]:mm")
Excel stores date/time as days and fractions of a day since 1/1/1900 where that date = 1
M3-L3 --> the difference in date/time
To format that result as hours:minutes, you use [hh]:mm
hh rolls over the hours every 24; [hh] will display the cumulative hours.
So, when you calculate (M3-L3) * 24, you are converting the stored value to hours. But [hh]:mm expects the value that you are formatting to be an actual date/time value. Hence the error.
In your second example, where you show the result of (m3-l3)*24 is 39.9; you have converted the time difference to decimal hours. 39.9 is 39 hours + 0.9 hours which is the same as 39 hours 54 minutes (0.9 * 60 minutes = 54 minutes)
You don't need TEXT function. Subtract one time from the another and format the cells with a custom format [h]:mm
(Rant: Excel's date and time formatting capabilities are very limited and difficult to work with - I'm sure it was great in comparison to other spreadsheet systems in the mid-1990s, but Microsoft has always been very conservative about updating Excel's core functionality - so even today, in 2020, Excel does not have a built-in formula function equivalent to DateTime.ParseExact and it ALWAYS prefers local computer settings which is bloody annoying as my computer is set to en-GB (but uses yyyy-MM-dd as my date-format override) so it's impossible to easily parse US-formatted date values, argh) - and there's still no support for consistently parsing ISO 8601 values, which is crazy for 2020.
Anyway - given this backstory on Excel's pathetic date and time formatting and parsing functionality, it's no surprise then that Excel doesn't support formatting hh as "total hours" - it always renders it in Modulo 24 (or Modulo 12 if you specify h)
(I retract the above statement because Ron's answer of [hh]:mm works, but it's still under-documented behaviour as it's not mentioned in Excel's documentation for TEXT() at all)
Assuming that L2 and M2 are being interpreted as Date+Time values correctly (I assume L2 is 2020-01-07 09:55 and M2 is 2020-01-09 01:49- and not 2020-01-07 09:55 and 2020-01-09 01:49 respectively), then try this:
Set N2's formula to = M2 - L2 - this should result in a floating-point Number value that represents the number of days-difference between the two dates.
Format it manually in O2 with this formula
= FLOOR( N2 * 24, 1 ) & ":" & ( ( N2 * 24 ) - TRUNC( N2 * 24 ) * 60 )
Update:
With my apologies to #RonRosenfeld, the examples given in the ExcelJet page do include a mention of using \[ and \] for formatting Elapsed Time values. The example is given as a screenshot which makes it impossible to search for (it's 2020 and search engines still don't do OCR on images - nor do browsers do Find-in-Page for images either). I'll repeat the information in text form so people can grep this answer:
From https://exceljet.net/custom-number-formats
Elapsed time is a special case and needs special handling. By using square brackets, Excel provides a special way to display elapsed hours, minutes, and seconds. The following screen shows how Excel displays elapsed time based on the value in D5, which represents 1.25 days:
A B C
Description Formula Formatted Value
-----------------------------------------------------------------------
1 Example elapsed time (days) =1.25 1.25
2 Elapsed hours (total hours) =TEXT(B1, "[h]") 30
3 Elapsed hours with minutes =TEXT(B1, "[h]:mm") 30:00
4 Elapsed minutes =TEXT(B1, "[m]") 1800
5 Elapsed minutes with seconds =TEXT(B1, "[m]:ss") 1800:00
6 Elapsed seconds =TEXT(B1, "[ss]") 108000
7 Elapsed seconds with milliseconds =TEXT(B1, "[ss].00") 108000.00
I cannot find any authoritative reference in Excel's documentation for the behaviour of [] when formatting numbers as durations - so technically this could be considered undocumented behaviour. That said, it probably is documented in the offline help files of older versions of Excel, I know a lot of useful documentation was lost when Office moved to all-online help between 2003 and 2013, grrrrrr.
Related
I have a date with hours and minutes like 2/3/2019 10:30 am , and I do the following to find the diffence in hours which I already formatted like ( h )
=now() - date
I want to check if the difference is more than 12 ( where I mean 12 hours) to do something.
if(actual difference>12; "hello"; "bye")
But is not checking the actual difference but the serial difference
How can I check the actual difference in hours?
Dates are stored as numbers where the integer part is the number of days since 1899-12-31. The fractional part measures the time within a day. So, 24 * (now() - date) will give you the number of hours elapsed.
NB: the formatting is only a question of display and won't influence what's done by the formulas.
In order to check conditionaly the difference in the hours unit between two times we can do if(hour(actual difference)>12; "hello"; "bye")
We put the function hour() as noted in
https://support.office.com/en-us/article/calculate-the-difference-between-two-times-e1c78778-749b-49a3-b13e-737715505ff6
I'm making something in excel which calculates my hours I work a week/month, when a number gets to 30.60 (two shifts which when finishing on the half an hour) it calculates it as 30.60*wage=not the right pay.
so far I have =ROUND(SUM(C6:I6),0) which rounds up the number, which works fine until I have another day which I work till half an hour then it will just show 16 or so.
As you can see here, it calculates it fine until I work 7.30 hours on a wednesday, the total shows 23.00 instead of 23.30.
How can this be done.
Thank you.
your problem is with excel understanding of your "hours". When you write 7.30 you mean 7 hours 30 minutes = 7.5 hours. But excel understands that as 7 hours and 30/100 of hour = 18 minutes. The easiest solution would be to use 7,5 for 7 hours 30 minutes.
(for sake of checking the question off the unanswered I copied my comment)
If you don't want to use 7.5 (Seven-and-a-half-hours) or 7:30 (7 hours, 30 minutes - but remember to multiply this by 24, since Excel stores this as the fraction of a day, 0.3125) then you can use INT and MOD:
=INT(C6)+(MOD(C6,1)/0.6)
The first part, INT(c6) will give you the Integer part (i.e. whole hours) which we don't want to scale/skew.
The second part has 2 stages. First, MOD(c6,1) will give us the Decimal part of the number (i.e. 7.3 will become 0.3) and the second part is to divide by 0.6 to convert from "fake-minutes" to "fraction-of-real-hour"
Finally, since you want to apply the formula to an array of cells, you will need to swap from SUM to SUMPRODUCT:
=SUMPRODUCT(INT(C6:I6)+(MOD(C6:I6,1)/0.6))
But, overall, best option is to use 7:30 and set Data Validation only allow actual Time values in that field.
{EDIT} Of course, this will give your output with 0.5 for 30 minutes. If you want to reverse back to 0.3 for 30 minutes (although, I can scarcely fathom why) then you need to run the same calculation in reverse:
=INT(SUMPRODUCT(INT(C6:I6)+(MOD(C6:I6,1)/0.6))) + 0.6*MOD(SUMPRODUCT(INT(C6:I6)+(MOD(C6:I6,1)/0.6)),1)
I'm trying to subtract start time from end time to get duration, ie:
1:02 - 0:10 = 0:52
But what I'm getting is:
0:92
I'm using the 0\:00 format. Other suggested formats, such as [mm]:ss, are turning my data into numbers that I don't undestand, ie 1:02 becomes 146880:00
I just want to quickly enter a bunch of times, subtract one col from the other and be done with it.
Does anyone know a way to do that?
Solutions follow an explanation of the results showing in the question.
The format 0\:00 is really the format 000 with a colon character inserted between the first and second digits.
If a cell holds the value 102 and has a format of 0:\00 it will show as 1:02 in the worksheet but behind the scenes its value is still 102. So
1:02 - 0:10 = 102 - 10 = 92 = 0:92 in 0\:00 format
To understand the result with the [mm]:ss format, you need to understand how dates (and time) values are represented in Excel. There is a reasonable explanation on this webpage from Chip Pearson
First, as a date/time value 102 is equivalent to 0:00 on 11 April, 1900 as it is 102 days from Excel's day/time zero. Second, the format [mm]:ss expresses this elapsed time in minutes and seconds. So
102 days = 102*24*60 minutes = 146880 minutes
which gets displayed as 146880:00 in [mm]:ss format
There are a couple of ways you might resolve your problem.
The first involves entering data differently. A time can be entered directly into the worksheet as hours:minutes:seconds. So 1 minute and 2 seconds can be entered as 0:1:2 (or 00:01:02 or any variant such as 0:01:2 or 00:1:02). This is probably less convenient than just entering 102. By default, numbers entered in this way will display in a hh:mm:ss format but you can suppress the display of hours by changing the format to mm:ss or [mm]:ss. The latter should be used if any of your time values are 60 minutes or more since, the former will suppress the display of hours - for example, entering 0:61:2 (61 minutes and 2 seconds) displays as 01:02 with the former but as 61:02 with the latter.
Note that if you just enter 1:2 rather than 0:1:2 Excel interprets this as 1 hour, 2 minutes and 0 seconds and will display as 02:00 using format mm:ss or as 62:00 using [mm]:ss.
The second way allows you to enter the data as before using the 0\:00 format but requires the use of formulae to convert your entered value into seconds - so, for example, an entered value of 102 is intended to represent 1 minute and 2 seconds, gets correctly displayed as 1:02 but is converted behind the scenes to 62 seconds.
If A1 and B1 contain the entered values the then formula for A1 less B1 is
=(INT(A1/100)*60+A1 - 100*INT(A1/100))-(INT(B1/100)*60+B1 - 100*INT(B1/100))
This formula calculates its result as a number of seconds.
If this result is placed in cell C1 then the formula
=100*INT(C1/60)+(C1-60*INT(C1/60))
converts C1 to a result suitable for displaying with the 0:\00 format
Alternatively, the result in seconds can be converted to days by dividing by 24*60*60 = 86400 and displayed using a time format such as [mm]:ss
I am doing some work in Excel and am running into a bit of a problem. The instruments I am working with save the date and the time of the measurements and I can read this data into Excel with the following format:
A B
1 Date: Time:
2 12/11/12 2:36:25
3 12/12/12 1:46:14
What I am looking to do is find the difference in the two date/time stamps in mins so that I can create a decay curve from the data. So In Excel, I am looking to Make this (if the number of mins in this example is wrong I just calculated it by hand quickly):
A B C
1 Date: Time: Time Elapsed (Minutes)
2 12/11/12 2:36:25 -
3 12/12/12 1:46:14 1436.82
I Have looked around for a bit and found several methods for the difference in time but they always assume that the dates are the same. I exaggerated the time between my measurements some but that roll over of days is what is causing me grief. Any suggestions or hints as to how to go about this would be great. Even If I could find the difference between the date and times in hrs or days in a decimal format, I could just multiple by a constant to get my answer. Please note, I do have experience with programming and Excel but please explain in details. I sometimes get lost in steps.
time and date are both stored as numerical, decimal values (floating point actually). Dates are the whole numbers and time is the decimal part (1/24 = 1 hour, 1/24*1/60 is one minute etc...)
Date-time difference is calculated as:
date2-date1
time2-time1
which will give you the answer in days, now multiply by 24 (hours in day) and then by 60 (minutes in hour) and you are there:
time elapsed = ((date2-date1) + (time2-time1)) * 24 * 60
or
C3 = ((A3-A2)+(B3-B2))*24*60
To add a bit more perspective, Excel stores date and times as serial numbers.
Here is a Reference material to read up.
I would suggest you to use the following:
Combine date to it's time and then do the difference. So it will not cause you any issues of next day or anything.
Please refer to the image with calculations. You may leave your total minutes cell as general or number format.
MS EXCEL Article: Calculate the difference between two times
Example as per this article
Neat way to do this is:
=MOD(end-start,1)*24
where start and end are formatted as "09:00" and "17:00"
Midnight shift
If start and end time are on the same day the MOD function does not affect anything. If the end time crosses midnight, and the end is earlier then start (say you start 23PM and finish 1AM, so result is 2 hours), the MOD function flips the sign of the difference.
Note that this formula calculates the difference between two times (actually two dates) as decimal value. If you want to see the result as time, display the result as time (ctrl+shift+2).
https://exceljet.net/formula/time-difference-in-hours-as-decimal-value
get n day between two dates, by using days360 function =days360(dateA,dateB)
find minute with this formula using timeA as reference =(timeB-$timeA+n*"24:00")*1440
voila you get minutes between two time and dates
I think =TEXT(<cellA> - <cellB>; "[h]:mm:ss") is a more concise answer. This way, you can have your column as a datetime.
I'm building a spreadsheet to calculate aircraft flying hours which will exceed 24. I am aware of the [h]:mm format to force Excel to not use units of days.
I want to set a threshold number of hours which I will subtract a running total from. However with the [h]:mm format set if I enter 1 in the cell, for 1:00, instead it interprets it as 24:00 - one day.
How can I avoid this, so that I can do simple arithmetic with hours and minutes exceeding a 24 hour period?
Type 1:0 or even just 1: instead of just 1
If you type 1 excel interprets this as the value 1, which is date serial value to 1 day (actually 1/1/1900)
If you type something that looks like a time (eg contains a :) then excel interprets it as a string representation of a time and converts it to the corresponding serial value (0.041666667 or 1/24) and applies the format so it displays as 1:00