I have two time:
9:29:00 AM (B2)
6:16:00 PM (C2)
I want to get the hh:mm (hours and minutes) between those two times. I tried the following function:
=TEXT(B2-C2,"h:mm")
But I get a #VALUE! error.
I formatted the two time cells as TIME format (*h:mm:ss am:pm) and result cell also as TIME format (hh:mm)
Is that the right way round? Try
=C2-B2
You don't need TEXT function
I believe your #VALUE error is due to your order of subtraction, but I can't be sure without knowing which of those times is B2 and which is C2, and I can't quite comment on your question yet, so an answer it is!
Times in excel are stored as doubles which increment by 1 each day; 0.5 is 12 hours etc.
Best thing to do is use =TEXT(B2-C2,"HH:MM")
This will format B2-C2 (a decimal number) as a time interval.
Of course the contents of B2 and C2 must be numeric; see my VALUE function in the comments.
As barry houdini mentioned back in 2013, I also ran into the error of subtracting giving a negative number, and excel just throws an error. No other response on the internet gave me good results. Although my method is longer, it always works with times in hh:mm:ss AM/PM. Just change the text format part of the formula for whatever you have. My data was:
11:15:45 PM 1:41:20 AM
I converted it to military time for ease with
=TEXT(A2, "hh:mm:ss")
Data was now:
23:15:45 01:41:20
I made another column, let's call it C, that just subtracts the second time from the first time,
=B2-A2
I next used an IF statement on this column, so that if the absolute value of the difference was the same as the number (a positive), I'd use
TEXT(B2-A2,"hh:mm:ss")
which just subtracts the later time from the earlier time. But...
If the absolute value of the difference was not the same, e.g. error-ville with a lot of hashes ##########, I use:
TEXT(24-(A10-B10),"hh:mm:ss")
Altogether, we have one more column, which finally spits out the correct hour difference. This column is predicated on columns A, B, and our error-prone difference column C:
=IF(C2=ABS(C2),TEXT(B2-A2,"hh:mm:ss"),TEXT(24-(A2-B2),"hh:mm:ss"))
this is the most ridiculous thing I have ever done. It's been years and such a simple case, never solved by Excel.
Related
I have the list of data that showing the Hours and the Minutes that I extract from the system. I need to be extract the hours.
As example below, column B first row, the Hours would be 64 and the minutes would be 46.
But when I used the formula =Hour , its turn up the different value since its actually decimal number.
Cannot use left() , it will give the actual decimal number.
Updated:
We tried the #harun24HR 's but cannot readable the value.
But if you noticed, if i copy and paste the value is different. thats why the search not applicable.
4th Update:
To Solar Mike, I have tried the formula given from the thread the i think the value not readable
It's a time value which Excel stores as calculated value based on 24 hours = 1.
To retrieve the hours only you can use:
=INT(A2*24)
To retrieve the minutes only you can use:
=(A1-(INT(A1*24)/24))*24*60
Your time value is already a number in time format so you just need it to change it to decimal system. Dates and time values are numbers. Even if you see it as 30/09/2019 or 12:00:00, actually, for Excel, both cases are numbers.
First date Excel can recognize properly is 01/01/1900 which integer numeric value is 1. Number 2 would be 02/01/1900 and so on. Actually, today is 44659.
Now, about your data, you posted this screenshoot:
So the value is numeric, not text/string. In Excel, what you see is not always what you have. Probably that column has been formatted using custom mask. My fake data is like this:
The numeric value is 02/01/1900 16:46:36 (or 02/01/1900 4:46:36 PM it depends on your regional settings) but I've applied a custom format like this:
[hh]" hours" mm " minutes"
So what I have is a number but what I see is a text!
We have to work with the number (to be honest, ist's easier to work with numbers), so to extract the total hours, minutes and seconds.
Formula in B1: =INT(A1*24) total hours
Formula in C1: =INT(A1*24*60-B1*60) total minutes
Formula in D1: =A1*24*60*60-B1*60*60-C1*60 total seconds
This should guide you on whatever are you trying to achieve.
From your current sample data you try-
For hour =LEFT(A2,SEARCH(" ",A2)-1)
For minutes =RIGHT(SUBSTITUTE(A2," minutes",""),2)
How do i calculate time difference in milliseconds between two columns where value of time has milliseconds component ... i.e. 16:33:44:056. Please refer to column E and J in pic .. i want to calculate difference in milli seconds between J and E ...
I have tried using the following formula to alculate difference in milli seconds but its giving incorrect results. =((RIGHT(J1,3))-(RIGHT(E1,3)))
It appears your date/time is a text value.
A "real" time value would normally be seen as 16:11:52.052
But by replacing the last : with a ., excel will see it as a real time and ordinary math can be done.
Excel stores date/time as days and fractions of a day.
So a formula that should work:
=ROUND((SUBSTITUTE(J1,":",".",3)-SUBSTITUTE(E1,":",".",3))*86400000,0)
Format the result as General or as Number with no decimal places
Try
=(J1-E1)*1000*60*60*24
or more concisely
=(J1-E1)*86400000
Then format your formula column to general.
This assumes the data is actually stored as datetime and not a text value.
If you change the format of your time columns, and the column to show the difference, to
hh:mm:ss.000
You can simply use subtraction:
(You'll have to tweak the actual cells to have . before the milliseconds, just formatting won't do it)
If the part of that string corresponding to hours, minutes and seconds is always the same, and time in J is always bigger than time in E, you could do:
=VALUE(RIGHT(J1;3))-VALUE(RIGHT(E1;3))
As requested, I have included a simplified screenshot that illustrates the issue.
As you can see, I subtracted the two dates and formatted it as "h:mm:ss". Why doesn't this give you the total amount of hours that have passed between the two dates? Is there a better way to do this? There is a great answer below, but I am trying to figure out why doing the way illustrated in this screenshot doesn't work.
END OF EDIT
I am aware that similar questions have been answered here, but for whatever reason this is not working for me at all.
I have two columns: one is a date, one is the time.
As you can see from the currently highlighted cell, the "time" column is actually stored as date with the time included. In column H, I have the date stored as a serial code so that the decimal number refers to a month, day, year, hour, minute, and second. When I subtract the serial code that refers to 2/16/2016 3:20:01 PM from the serial code that refers to refers to 2/14/2016 1:20:01 PM and format that cell as "h:mm", I am getting 2:00. Why?????
I have been hacking away at this for a while and this is supposed to be stupid easy and it's not working. Any help is greatly appreciated so I can move on to more important things.
It does work. Just take the difference between the two dates, format the cell containing the difference as Number, and then use one of the following formulas to get the units you want. I will assume that:
A1 has the value 2/16/2016 3:20:01 PM
B1 has the value 2/14/2016 1:20:01 PM
Into C1 enter A1 - B1, and format it as Number
If you want the difference as days, leave C1 as is.
If you want hours, use =24*(A1 - B1)
If you want minutes, use =24*60*(A1 - B1)
If you want seconds, use =24*60*60*(A1 - B1)
THE ANSWER TO THIS IS REALLY SILLY.
Below, you will find that Tim Biegeleisen provided an excellent answer to this question. I just wanted to further elaborate.
Sometimes having too many option for formatting can be a problem, which is what happened here.
When you subtract 2/14/2016 1:20:01 PM from 2/16/2016 3:20:01 PM and format it as h:mm:ss it only subtracts the hours portion and ignores days. You just have to somehow know that if you are trying to do what I'm trying to do, you have to format it as [h]:mm:ss and then it will calculate the total number of hours passed. The bracket around the "h" is the important part here. I hope this helps the next person who comes across this.
I have some columns where the date values are in integer format, i.e.14.06736111
for 1:37. I want to get the format into minutes.
I tried using the [m[ format in custom format, and that works on many of the cells, but some of them throw out crazy numbers. For example, for the cell where the time is 1:37 I am getting 20257 instead of 97. It looks like the cells that have wacky values also have a nonsense date string attached (1/14/1900).
I can use find/replace to remove the date string and the the format works again, but that seems inefficient.
Is there a better way around this?
Your 14.06736111 is not a time; it's a date (01/14/1900) with a time (.06736111 of a 24-hour period). I'm guessing that the date portion is incorrect, or you're not actually seeing a date value at all.
To display just the time, your cell first needs to remove the integer part of the date (the part to the left of the decimal point). If your date value is in cell A1 as 14.06736111:
=A1-Int(A1)
#nutsch points out in a comment below that a shorter means of doing this would be
=MOD(A1, 1)
Set the cell formatting to Time:
1:37:00AM
Using =A1-Int(A1) as suggested by Ken White helped a lot, but I was still having problems. Through a bit of trial and error I found that the best way to convert an fractal time value into whole minutes was to use the following formula:
=FLOOR(A1/0.000694, 1)
I am trying to calculate the hour difference between two times. What I've been doing now only gives me hour indications like 1:30, 2:45, etc but I can't make diagrams based on these values. If I get 2:30 as the hour difference, it should become 2,5. if the difference is 2:45 that should be 2,75.
Change your formula to:
(B2-A1)*24
and format as General
You should just be able to subtract 1 datetime from the other. Try this:
In cell A1, enter "09/17/2012 10:00" (Excel should automatically recognize this as a date)
In cell A2, enter "09/17/2012 11:30"
In cell A3, "=(A2-A1)*24". The result is 1.5.
The problem may be that you are trying to subtract 1 'time' from another 'time' without a date component. In that case, Excel may not recognize your value as a 'time'. Try adding a dummy date to the beginning of the time.
One limitation of this is that you will get an error response of "########" if the 2nd date is earlier than the 1st (because the result is negative). If this is an issue, try "=ABS(A2-A1)*24" instead.