I have the folowing formula:
=IF(TIMEVALUE("14:30") - TIMEVALUE(NOW()) < TIMEVALUE("00:00"),"Past","Future")
Excel is giving me ERROR, i checked all formulas individually and they all give me the time value (which in theory should be enough to compare with an IF statement).
How come that i keep on getting error. Some cell formats not correct or something? Any help is appreciated!
Try to evaluate the formula step by step to see, if this is what you want.
Working formula:=IF(TIMEVALUE("14:30") - NOW() < TIMEVALUE("00:00");"Past";"Future")
Evaluated arguments, using [F9 key]:=IF(0,604166666666667 - 42719,6943635416 < 0;"Past";"Future")
You will always get the "Past"
as returned value.
Explanation of date and time in Excel
The TIME in Excel is a proportion of a day. "00:00" = 0.00
and "24:00" = 1.00
. Other values of TIME are DECIMALS between 0 and 1.
The DATE is a number of days since the first day. "1900-01-01" = 1
and "2000-01-01" = 36526
. It is always an INTEGER.
Combining DATA and TIME (like in NOW()
function) gives you an INTEGER + DECIMAL. When I evaluated the NOW()
it returned 42719,6943635416
The TIMEVALUE
function expects a STRING/TEXT that is considered a TIME and converts that STRING/TEXT to DECIMAL between <0; 1>.
Links
MS - How to use dates and times in Excel
Trump-Excel:Identify Errors Using Excel Formula Debugging (2 Methods)
Convert the Now
to string first, using Text
function, then it will work as expected.
TEXT(NOW(),"HH:MM:SS")
Final formula:
=IF((TIMEVALUE("11:30") - TIMEVALUE(TEXT(NOW(),"HH:MM:SS"))) < TIMEVALUE("00:00"),"Past","Future")
来源:https://stackoverflow.com/questions/41167296/use-if-with-timevalue-in-excel