I have a simple case:
my j9-cell has formula: =h9-g9
when h9 has value 17:30 and g9 has value 17:00 j9 results 00:30 ... its ok!
but when h9 has value 16:30 it crashes..
Instead of showing -00:30 (as I expected) it shows a lot of #.
Am I missing something in formula? Thanks in advance.
Your calculation is producing a negative value, which constitutes an invalid date/time.
One way to fix it is to switch to the "1904 date system". To do this, select the "File" tab, then select "Options", then select "Advanced", then find the "Use 1904 date system" checkbox, and select it (this works when using Excel 2010 and newer).
Another way to fix it would be to change your formula to:
=IF(h9-g9<0, "-" & TEXT(ABS(h9-g9),"hh:mm"), h9-g9)
Warning: This produces a text value which may not be valid when used in other calculations.
What I would use:
=IF(H9>G9;"";"-")&TEXT(ABS(H9-G9);"h:mm")
This will generate the elapsed time as a text value, also if it's a negative result.
And since the result will always be a text, the format of the calculated field doesn't have to be changed to time.
Note: On a Dutch version of Excel the TEXT() formatting must be "u:mm" to make this work.
Excel does not appreciate negative time. You might want to incorporate a date into your calculations or possibly (maybe with a formula such as =IF(H9>G9,H9-G9,1+G9-H9) format 'negative' time results in red with conditional formatting, or use fractions of a day instead of time.
An addition to Mr. TL Couger's equation.
=IF(G8-E8<0,"-"&TEXT(ABS(G8-E8),"hh:mm"),TEXT((G8-E8),"hh:mm"))
Using this equation will always format a time difference(positive or negative) to a 00:00.
Related
I'm trying to highlight the time based on the folowing rules
If the time is lower than 7:30 be closer to red
Otherwise if the time is closer to 8:05 get close to green
In this sheet:
I guess it's easier to explain with the following illustration:
You should get the basic idea of what I'm trying to accomplish with the formulars in the formatting rule picture. That one however doesn't work.
Any ideas what would be the proper way to format this rule?
On the left side for value write 0,31 and on the right side write 0,34.
To get the correct value, that is corresponding to the correct time, simply select the time in Excel, using the Time() formula, press Ctrl+1 and select Number. You will see the correct number for the time.
Also found a way, albeit this is more of a workaround:
You can enter the values as a raw number in format of AB:CD:EF (or depending on the time format you are using) and excel will automatically format the rule somehow with decimal signs, although this really is more of a workaround rather than answer to the actual question
You can use "industrial minutes", minutes to a base of 100 industrialseconds. Then you can use standard decimal values.
In excel you simple multiply time values by 24 to get to that. Then 30 minutes are 0.5 of an hour.
For the conditional formating use a 3-Color scale and set the middlepoint to number 7.5 and a lighter green.
I would like to make a condition to use IF formula when the cell A1 with a date in this format YYYY-MM-DD 20:30 has the time higher than 18:30 (date is not important and should not be taken in consideration).
For example 2000-01-22 20:30 follows under this condition and 2015-02-22 15:30 doesnt.
Any tip?
Thank you a lot.
You can rely on the underlying decimal representation of datetimes in Excel. Just check if the decimal part of your date is greater than [your time]/24.0 :
=if(MOD(A1,1) > 18.5/24, TRUE, FALSE)
How's this (if your data is in cell A1, place this in B1):
=IF(AND(HOUR(RIGHT(A1,5))>=18,MINUTE(RIGHT(A1,5))>=30),"After 6:30 PM","Before")
Note: This includes 18h30. To exclude it, just change the equation to simply >.
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.
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.
Have a list of dates in excel in the format (this comes originally from csv):
23/11/09 07:27:02
23/11/09 08:01:50
23/11/09 08:38:58
23/11/09 09:40:01
What I want to do is count the number of these falling between hour blocks, like 7-8, 8-9, 9-10 etc
Not sure how to get started, but one idea was just to put logic statements comparing the dates between these blocks, then adding the total "trues"
I can't get it to compare properly. When I type it the hour block marks,
e.g. 23/11/09 08:00
excel actually shows that as
23/11/2009 8:00:00 AM
and the compare doesn't work. Well actually it does the opposite of what it should.
that is:
=IF(C5>L1,IF(C5<M1,TRUE,FALSE),FALSE)
C5 being date in top codeblock, L1 and M1 being the hour blocks I manually entered in the second code block.
Has anyone got any ideas?
=hour(a1)=7
will return true if the time of the date/time value in cell A1 is between 7 and 8 (AM) and will otherwise return false.
Excel stores dates as number of days since 1900 or 1904 depending on your setting and the time as a fraction of the days. So 11:59 am 4th of July 1960 is held internally as '22101.4993055556'.
As such you cannot do plain charactrer string comparisons on dates. However ther ar lots of nifty time/date functions available to you.
You probably want :
=IF(HOUR(B1) > 8,IF(HOUR(B1)<12,"YES","NO"),"NO")
You should use Excel functions, like HOUR(), to extract the parts of the times, and apply the logic tests to those extracted values.