简体   繁体   English

比较日期中的日期是否在今天的日期之前

[英]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.

相关问题 获取从今天开始的月份和年份 - Get the month and year from today's date 如何编写Excel公式以比较年初至前几年并计算闰年? - How do I write an Excel formula to compare year-to-date to prior years & also account for leap years? Excel VBA-等效的上一年日期 - Excel VBA - Equivalent Prior Year Date 检查日期是否在今天的日期之前2个月 - Check if Date is 2 months prior to today's date VBA Match功能使用今天的日期来搜索去年的条目 - VBA Match function using today's date to search for last year's entry Excel:获取给定年份的开始日期和结束日期之间的月份,或者如果开始日期在上一年中则获得截止日期为止的月份 - Excel: get months between start and end date in given year or months through end date if start is in a prior year 年初至今本月和上一年的总和 - Sum current and prior year month-to-date to corresponding day of month 我需要什么 function 才能获得比上一年年初至今的百分比增长? - What function do I need for getting year-to-date % increase over prior year? 根据 excel 中今天的年份和月份列突出显示整行 - highlighting entire row based on today's year and month columns in excel SQL 比较在访问今天的日期时所持有的日期不起作用 - SQL to compare date held in access to today's date not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM