Date comparison not working in Excel formula

匿名 (未验证) 提交于 2019-12-03 02:20:02

问题:

If I put the date 31/12/2013 in A1 and another date 1/1/2014 in A2 then a formula like

 =A1<A2  

gives the expected result, TRUE.

If I put the formula

=A1<1/1/2014  

in another cell, it gives the result FALSE.

The question is how to adjust the second formula to make it give the correct result, and why it doesn't work as it stands.

I've been looking at this for a while and have found some related posts like

Comparing computed dates with entered dates

but not one which directly answers the question.

回答1:

1/1/2014 is 1 divided by 1 divided by 2014.

Instead; =A1<DATEVALUE("1/1/2014")



回答2:

I can answer my own question now.

The answer as mentioned in related posts is to use the DATE or DATEVALUE functions i.e.

=A1<date(2014,1,1) 

or

=A1<datevalue("1/1/2014") 

The reason it doesn't work is that in this context Excel just sees 1/1/2014 as an arithmetic expression, one divided by one divided by 2014 which is a small number. Dates (number of days since 1/1/1900) generally evaluate to large numbers so the comparison fails.

If you just type 1/1/2014 into a cell you get a date, but if you type =1/1/2014 you get a small number.

I just thought it was interesting to share because to a human =A1<1/1/2014 looks as if it's comparing a cell with a date, but it isn't.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!