[英]Compare if year in date is prior to today's year
I have a date in the format of "4/26/2013". 我有一个日期为“ 4/26/2013”的日期。 I want to see if that date is prior than the current year, whatever that current year may be (don't want to hardcode 2013) and count how many of the rows match that criteria. 我想看看该日期是否早于当前年份,无论当前年份是什么(不想硬编码2013),并计算有多少行符合该条件。 Say there are 6 rows of dates in that format: 假设该格式有6行日期:
=COUNTIF(C2:C7, YEAR(Today()))
This threw an error. 这引发了错误。 I'm new to Excel, so I probably made a huge mistake! 我是Excel的新手,所以我可能犯了一个大错误! Can anyone see what is wrong with this? 谁能看到这有什么问题吗?
Thanks! 谢谢!
If C2:C7 contain dates you need to compare them to the 1st of January in the current year, eg 如果C2:C7包含日期,则需要将其与当年1月1日进行比较,例如
=COUNTIF(C2:C7,"<"&DATE(YEAR(TODAY()),1,1))
or you can use SUMPRODUCT like this 或者您可以像这样使用SUMPRODUCT
=SUMPRODUCT((YEAR(C2:C7)<YEAR(TODAY()))*(C2:C7<>""))
I just figured it out. 我只是想通了。 My syntax was wrong. 我的语法错误。 The answer to the above example was: 上面示例的答案是:
=COUNTIF(C2:C7, ">"&YEAR(TODAY()))
That returned the number of dates in C2 - C7 that were prior to the current year. 这将返回C2-C7中当前年份之前的日期数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.