Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Excel Counting Months: COUNTIF, DATEDIF & Month Formulas

· 7 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

To count months in Excel you have three jobs to separate: counting how many times a given month appears in a list of dates, counting how many whole months fall between two dates, and counting dates that fall within a specific month of a specific year. For the first, use SUMPRODUCT with the MONTH function or a helper column plus COUNTIF. For the second, use DATEDIF(start, end, "m"). For the third, combine COUNTIFS with lower and upper date boundaries. Each method is explained below with exact formulas you can paste in.

What You'll Need

  • A version of Excel that supports SUMPRODUCT, COUNTIF, COUNTIFS and DATEDIF (Excel for Microsoft 365, Excel 2021, 2019, 2016, or Excel for the web all work).
  • Dates stored as real Excel dates, not as text. Excel dates are numbers, so a cell that reads "01/03/2026" but is left-aligned is almost certainly text and will break every formula below.
  • A column of dates to work from, and one cell for your start date and one for your end date if you are counting months between two dates.

Step-by-Step

  1. Confirm your dates are genuine dates. Select the date column and check the alignment: real dates align right by default, text aligns left. You can also apply a short date number format. If they are text, fix them before going further, for example with Data > Text to Columns, choosing Delimited and then picking the Date column type on the third screen. Note that menu labels can differ slightly by Excel version and by Windows, macOS or the web app.
  2. Count entries in a specific month with COUNTIFS. This is the safest method because it avoids array formulas. Put your year in one cell, say G1, and the month number in G2. Then in another cell enter:
    =COUNTIFS(A2:A100,">="&DATE(G1,G2,1),A2:A100,"<"&DATE(G1,G2+1,1))
    This counts every date on or after the first of that month and before the first of the next month, which correctly handles months of different lengths and leap years.
  3. Count a month regardless of year with SUMPRODUCT. If your list spans several years and you only care about, say, all of March, use:
    =SUMPRODUCT(--(MONTH(A2:A100)=3))
    Change 3 for the month you want, or point it at a cell containing the month number. The double negative turns the TRUE/FALSE results into ones and zeros that SUMPRODUCT adds up. Do not type the curly braces yourself; this formula does not need Ctrl+Shift+Enter in modern Excel.
  4. Add a helper column if you prefer plain COUNTIF. In a spare column, enter =MONTH(A2) in the first row and fill down. Then count with =COUNTIF(B2:B100,3). This is easier to read, easier to audit and works in every version. For a month-and-year count, use =TEXT(A2,"YYYY-MM") in the helper column and count the resulting text such as "2026-03".
  5. Count whole months between two dates with DATEDIF. With a start date in D2 and an end date in E2, enter:
    =DATEDIF(D2,E2,"m")
    The result is the number of complete months elapsed. If the start date is later than the end date, this returns an error, so check the order of your cells. DATEDIF still works in Excel but is not listed in the function gallery, so type it manually rather than browsing for it.
  6. Get a rounded-up month count when you need part-months. For billing or proration you often want any started month to count. Use =DATEDIF(D2,E2,"m")+(DAY(E2)>=DAY(D2)) to add a month when the end day is on or past the start day, or the alternate form =(YEAR(E2)-YEAR(D2))*12+MONTH(E2)-MONTH(D2) for a straight calendar-month difference. Test both against a few known pairs before trusting them.
  7. Build a month-by-month summary table. Type the first of a month in a cell and drag the fill handle down to create a series of first-of-month dates. In the next column, reuse the COUNTIFS formula from step 2 with the summary date as both the year and month source: =COUNTIFS($A$2:$A$100,">="&B2,$A$2:$A$100,"<"&EDATE(B2,1)). EDATE returns the same day in the next month and handles year rollover automatically, which makes this the cleanest approach for a rolling report.
  8. Verify one number by hand. Filter the list to a single month using the date filter options, read the status bar count at the bottom of the screen, and compare it with your formula result. If they differ, you have a text-date or blank-cell problem.

Common Mistakes

Dates stored as text. By far the most frequent cause of a zero or wrong result. Any formula that uses MONTH, DATE or comparison operators against a real date fails silently on text. Convert first.

Typing the month as a name. =COUNTIF(A2:A100,"March") will not work on a column of proper dates, because the cell values are serial numbers, not the word March. Count with the boundaries or the month number instead.

Using > and < without the first-of-month logic. Writing >=1/3/2026 and <=31/3/2026 typed as text or with mismatched day order gives unpredictable results and can miss or duplicate entries. Always build the boundaries with DATE or EDATE.

Forgetting absolute references. When you copy a COUNTIFS formula down a summary table, unfixed ranges like A2:A100 shift and start counting the wrong cells. Lock them with dollar signs.

Assuming DATEDIF rounds. It truncates. Two dates a day short of a full month return the lower number, which surprises people doing lease or subscription calculations. Decide deliberately whether to round up.

Leaving blanks in the range. Blanks are treated as zero, or as January in the MONTH sense, depending on the formula, and can inflate counts. Size ranges to your actual data or wrap the test with a check such as (A2:A100<>"").

Tips

Name your date range with Formulas > Name Manager and use the name in formulas; it makes summaries far easier to read and maintain.

Use EDATE and EOMONTH rather than manual day arithmetic. EOMONTH(date,0) gives the last day of that month, which is handy for month-end boundary checks.

Format the first-of-month cells as "mmm yyyy" so the summary table reads clearly while still holding a real date underneath.

If you need a count of months, not dates, remember that a difference in calendar months is not the same as elapsed time. Pick the definition that matches your business rule and document it in a cell comment.

Troubleshooting

The formula returns 0. Check date types first, then confirm the range actually contains the month you asked for. A COUNTIFS boundary built with DATE(G1,G2+1,1) will fail if G2 contains a month name or text such as "03 " with a trailing space.

You get #VALUE!. Something in the range is text. Filter the column for non-dates or use ISNUMBER in a helper column to spot the offenders quickly.

DATEDIF gives #NUM!. The start date is after the end date. Swap the cells or add a guard such as IF(E2<D2,"",DATEDIF(D2,E2,"m")).

Counts look double. You may have the same date listed with a time component, or your range overlaps two formulas in the summary table. Check for duplicate rows and confirm each summary row uses its own month boundary.

SUMPRODUCT is slow. Whole-column references such as A:A force Excel to evaluate over a million rows. Limit the range to your data, or switch to the COUNTIFS method, which is normally faster.

Frequently Asked Questions

Can I count months by name without changing the dates?

Yes. Use =SUMPRODUCT(--(TEXT(A2:A100,"mmmm")="March")), or count the month number with MONTH as shown above. The TEXT approach is language-dependent, so it only matches if your Excel regional settings produce that month name.

Why does DATEDIF not appear in the function list?

It is kept for compatibility with older spreadsheets and is not offered in the function browser. You can still type it directly and it calculates correctly.

How do I count months between two dates rounded up?

Take the DATEDIF result and add one when the end day is on or after the start day, or use the year-and-month arithmetic formula given in the steps. Test both on cases such as 31 January to 1 February before relying on them.

Does this work in Excel for the web and Google Sheets?

COUNTIFS, SUMPRODUCT, MONTH and EDATE behave the same in Excel for the web and in Google Sheets. Google Sheets also supports DATEDIF, though the result on edge cases can differ, so verify a couple of known pairs if you move a file across.

Can I count months where a cell is blank?

Blanks can be interpreted as zero and counted as January by some formulas. Add a non-blank condition, for example by including (A2:A100<>"") inside SUMPRODUCT, or exclude them with COUNTIFS by requiring the date range to be greater than zero.

How do I count unique months in a list?

Create a helper column with =TEXT(A2,"YYYY-MM"), copy it, and paste as values into a new column, then use Data > Remove Duplicates to see the distinct months. A dynamic-array formula with UNIQUE also works in Microsoft 365.