简体   繁体   English

日期范围内的日期

[英]Dates in a range excel

I am trying to use an IF statement in Excel to find if a particular date is within a specific range. 我正在尝试在Excel中使用IF语句来查找特定日期是否在特定范围内。 I have the cell A2 containing the date 1/2/2014 . 我的单元格A2中包含日期1/2/2014 In another cell the formula I used is: 在另一个单元格中,我使用的公式是:

=IF(AND(A2>="1/1/2014",A2<="1/15/2014"),"TRUE","FALSE")

This always outputs FALSE. 这总是输出FALSE。 Does anyone know why the this expression is not recognizing that the date is within the specified range? 有谁知道为什么这个表达式不能识别日期在指定范围内?

You are comparing strings of character. 您正在比较字符串。 You would be better off comparing the result of the DATE() function and pass it the day, month and year. 您最好比较一下DATE()函数的结果并将其传递给日,月和年。

=IF(AND(A2>DATE(2014,1,1), A2<=DATE(2014,1,15)), "TRUE", "FALSE")
=AND(A2>=41640,A2<=41654)  

might be sufficient. 可能就足够了。 If times could be involved you might want <41655 rather than <=41654 . 如果可能涉及时间,则可能需要<41655而不是<=41654

You need to convert the dates in your formula into "real" dates. 您需要将公式中的日期转换为“实际”日期。 The comparison operater won't do that. 比较运算符不会这样做。 A double unary, the DATEVALUE function, or using the DATE function (as per Levasseur's answer) will 一个双精度的DATEVALUE函数或使用DATE函数(根据Levasseur的回答)

=IF(AND(A2>=--("1/1/2014"),A2<=--("1/15/2014")),"TRUE","FALSE")

or 要么

=IF(AND(A2>=DATEVALUE("1/1/2014"),A2<=DATEVALUE("1/15/2014")),"TRUE","FALSE")

These two methods have the disadvantage of being dependent on the date format being used on your machine. 这两种方法的缺点是取决于计算机上使用的日期格式。

A better option would be to put the start and end date of the range into two different cells, and use that in your formula 更好的选择是将范围的开始日期和结束日期放入两个不同的单元格,然后在公式中使用

eg 例如

A1:  1/1/2014
B1:  1/15/2014


=IF(AND(A2>=A1,A2<=B1),"TRUE","FALSE")

or, shorter: 或更短:

=IF(AND(A2>=A1,A2<=B1),TRUE)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM