COUNTIF With Dates: Before, After and Between
By ExcelReady TeamUpdated 6 min read
The short answer
To count dates in Excel, join an operator to a date built with DATE: =COUNTIF(B2:B8,">="&DATE(2024,3,1)) counts dates on or after 1 March 2024. Use "<" for before. To count between two dates, use COUNTIFS with two conditions: =COUNTIFS(B2:B8,">="&DATE(2024,3,1),B2:B8,"<="&DATE(2024,3,31)). Build dates with DATE rather than typing them as text, which depends on regional settings.
Key takeaways
- Build criteria dates with DATE(year,month,day) and join the operator with &: ">="&DATE(2024,3,1).
- Typing a date as text inside the criteria depends on regional settings, so avoid it.
- Count between two dates, or within a month, with COUNTIFS and two conditions on the same column.
- With a date in a cell, use ">="&E1, never ">=E1".
- If the dates include times, count up to the next day with "<" instead of "<=" the last day.
On this page+
- How dates work in COUNTIF criteria
- How to count dates before or after a date
- How to count dates between two dates
- How to count dates in a month
- How to use dates from cells
- How to count dates relative to today
- Why COUNTIF with dates returns 0 or the wrong count
- How to count dates with a second condition
- Practise it
A COUNTIF date formula in Excel counts the dates before, after or between the days you choose. The key is to build the date with DATE and join it to the operator with &, as in =COUNTIF(B2:B8,">="&DATE(2024,3,1)). This guide shows each kind of date count on one small ticket log, plus whole months, dates in cells, today's date and the reasons a date count returns 0.
How dates work in COUNTIF criteria#
Excel stores every date as a number: the count of days since 1 January 1900. 1 March 2024 is the number 45352, shown in a date format. So counting dates is really counting numbers, and the same operators work: >, <, >=, <= and <>.
The safest way to write a date in a criteria is the DATE function, DATE(year, month, day), joined to the operator with &:
">="&DATE(2024,3,1)You may see criteria like ">=3/1/2024". Excel tries to read that text as a date using your computer's regional settings, so 3/1 is 1 March in the US but 3 January in the UK. DATE always means the same day everywhere.
Every example uses this ticket log in A1:B8:
| A | B | |
|---|---|---|
| 1 | Ticket | Opened |
| 2 | T-201 | 26 Feb 2024 |
| 3 | T-202 | 1 Mar 2024 |
| 4 | T-203 | 8 Mar 2024 |
| 5 | T-204 | 15 Mar 2024 |
| 6 | T-205 | 29 Mar 2024 |
| 7 | T-206 | 2 Apr 2024 |
| 8 | T-207 | 15 Apr 2024 |
How to count dates before or after a date#
Use COUNTIF with one condition. These are the common forms:
| Question | Formula | Result |
|---|---|---|
| On or after 1 Mar 2024 | =COUNTIF(B2:B8,">="&DATE(2024,3,1)) | 6 |
| Before 1 Mar 2024 | =COUNTIF(B2:B8,"<"&DATE(2024,3,1)) | 1 |
| After 15 Mar 2024 | =COUNTIF(B2:B8,">"&DATE(2024,3,15)) | 3 |
| On or before 15 Mar 2024 | =COUNTIF(B2:B8,"<="&DATE(2024,3,15)) | 4 |
| Exactly 15 Mar 2024 | =COUNTIF(B2:B8,DATE(2024,3,15)) | 1 |
Watch the difference between > and >=. "After 15 March" with > leaves out T-204, which was opened on 15 March. "On or before 15 March" with <= keeps it. Together they cover all seven tickets: 3 + 4 = 7. If COUNTIF itself is new, start with how to use COUNTIF.
How to count dates between two dates#
COUNTIF takes one condition, so for a date range use COUNTIFS with the same column twice: one condition for the start and one for the end.
=COUNTIFS(B2:B8,">="&DATE(2024,3,1),B2:B8,"<="&DATE(2024,3,31))The result is 4: T-202, T-203, T-204 and T-205. A date is counted only when it passes both tests. The COUNTIFS function guide lists the arguments, and COUNTIF vs COUNTIFS explains the difference between the two functions. The same between pattern works for any numbers, as shown in COUNTIF between two numbers.
How to count dates in a month#
To count a whole month, count from its first day to its last. EOMONTH finds the last day for you, so you don't need to remember whether a month has 30 or 31 days. With 1 Mar 2024 in E1:
=COUNTIFS(B2:B8,">="&E1,B2:B8,"<="&EOMONTH(E1,0))EOMONTH(E1,0) returns 31 March 2024, the end of the month that E1 is in. The result is 4. Change E1 to 1 Apr 2024 and the count becomes 2 (T-206 and T-207).
To build a monthly summary, list the first day of each month down column E, put this formula next to the first one with the range locked as $B$2:$B$8, and fill down (Windows: Ctrl+D; Mac: ⌘D). To total amounts by month instead of counting rows, see how to sum by date range or month.
How to use dates from cells#
Put the start and end dates in cells so anyone can change the period. With the start date in E1 and the end date in F1:
=COUNTIFS(B2:B8,">="&E1,B2:B8,"<="&F1)The operator stays inside quotes and the cell reference stays outside, joined with &. Writing ">=E1" is the most common mistake: inside quotes, E1 is just text, so the formula returns 0.
How to count dates relative to today#
TODAY returns the current date, so you can join it to an operator just like DATE:
| Question | Formula |
|---|---|
| Dates before today (overdue) | =COUNTIF(B2:B8,"<"&TODAY()) |
| Dates from today onwards | =COUNTIF(B2:B8,">="&TODAY()) |
| Dates in the last 30 days | =COUNTIFS(B2:B8,">="&TODAY()-30,B2:B8,"<="&TODAY()) |
These results change every day, which is the point for a tracker of overdue tasks. For a fixed report, use DATE instead so the numbers stay the same when someone opens the file next month.
Why COUNTIF with dates returns 0 or the wrong count#
Work through these causes:
- Cell reference inside the quotes. Use
">="&E1, not">=E1". - Dates stored as text. Imported dates are sometimes text, which COUNTIF can't compare as numbers. Real dates sit on the right of the cell by default. Fix them with Data > Text to Columns or DATEVALUE.
- Dates with times. A value like 31 Mar 2024 14:30 is bigger than 31 March at midnight, so
"<="&DATE(2024,3,31)misses it. Use"<"&DATE(2024,4,1)as the end condition instead. - Text dates in the criteria.
">=1/3/2024"may be read as 3 January instead of 1 March. Use DATE. - Blank cells. COUNTIF with
"<"&DATE(...)doesn't count blanks, but a criteria like"<>"&DATE(...)does. To count only filled cells, see COUNTIF not blank.
How to count dates with a second condition#
COUNTIFS can mix date conditions with conditions on other columns. Say column C holds each ticket's status:
| Ticket | Opened | Status |
|---|---|---|
| T-202 | 1 Mar 2024 | Closed |
| T-203 | 8 Mar 2024 | Open |
| T-204 | 15 Mar 2024 | Closed |
| T-205 | 29 Mar 2024 | Open |
To count the March tickets that are still open, add a third pair:
=COUNTIFS(B2:B8,">="&DATE(2024,3,1),B2:B8,"<="&DATE(2024,3,31),C2:C8,"Open")The result is 2 (T-203 and T-205). A row counts only when every condition is TRUE.
Practise it#
Dates in criteria are where many people get stuck, because of the & join and the hidden times. Practise dates in criteria in a live spreadsheet, and brush up on the basics with the COUNTIF lesson. Each lesson checks your formula instantly. Or count the March tickets in the exercise on this page.
Try it yourself
This is a live spreadsheet. Type the formula in the green cell and press Enter.
How many tickets were opened in March 2024? In E2, use COUNTIFS on B2:B8 with ">="&DATE(2024,3,1) and "<="&DATE(2024,3,31).
| A | B | C | D | E | F | |
|---|---|---|---|---|---|---|
| 1 | Status | |||||
| 2 | March 2024 | |||||
| 3 | Closed | |||||
| 4 | Open | |||||
| 5 | Closed | |||||
| 6 | Open | |||||
| 7 | Open | |||||
| 8 | Closed | |||||
| 9 | ||||||
| 10 | ||||||
| 11 |
Tip: Use B2:B8 twice. The first criteria is ">="&DATE(2024,3,1) and the second is "<="&DATE(2024,3,31).
Practise this in a lesson
Frequently asked questions
How do I count dates after a certain date in Excel?
Use COUNTIF with an operator joined to DATE: =COUNTIF(B2:B8,">"&DATE(2024,3,15)). This counts the dates after 15 March 2024. Use ">=" to include that day.
How do I count dates between two dates?
Use COUNTIFS with two conditions on the same range: =COUNTIFS(B2:B8,">="&DATE(2024,3,1),B2:B8,"<="&DATE(2024,3,31)). A date is counted only when it passes both tests.
How do I count dates in a specific month?
Count from the first day of the month to the last day. With the first day in E1, use =COUNTIFS(B2:B8,">="&E1,B2:B8,"<="&EOMONTH(E1,0)). EOMONTH finds the last day of that month.
How do I count dates before today?
Join the operator to TODAY: =COUNTIF(B2:B8,"<"&TODAY()). The result changes each day, which is useful for counting overdue items.
Why does COUNTIF with dates return 0?
Common causes are a cell reference written inside the quotes, dates stored as text, or dates that include a time. Check that the dates sit on the right of their cells, which shows they are real dates.