Date Same Month and Year? Check Here
The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.
This calculator checks whether two dates fall in the same month and year. You enter two dates, and it returns a clear yes or no, along with the month and year of each date for verification. It is useful for sorting records, verifying billing cycles, or checking if events occurred in the same calendar month.
Formula
The check is simple: compare the year and month of both dates. Convert each date to a single integer by multiplying the year by 100 and adding the month number (1–12). If the two integers are equal, the dates share the same month and year.
For date d, the key value is:
Key = YEAR(d) × 100 + MONTH(d)
Where YEAR(d) is the four-digit year and MONTH(d) is the month number (1 for January, 2 for February, etc.). The calculator outputs 1 if the keys match, 0 otherwise.
Worked Example
Using the default dates: 2024-03-15 and 2024-03-20.
- First date: YEAR = 2024, MONTH = 3 → Key = 2024 × 100 + 3 = 202403
- Second date: YEAR = 2024, MONTH = 3 → Key = 2024 × 100 + 3 = 202403
- Keys are equal → Output = 1 (Yes)
Both dates are in March 2024, so the answer is yes.
When to Use This Check
This comparison is common in data cleaning, finance, and project management. For example, you might need to verify that two transactions occurred in the same billing month, or that two events fall within the same calendar month for reporting. It is also handy when merging datasets where you need to match records by month and year only, ignoring the day.
The check is purely calendar-based; it does not consider time zones or daylight saving. If you need to compare across time zones, you should first convert both dates to a common time zone, then run the comparison.
How to Read the Result
The main output is a binary flag: 1 means the dates are in the same month and year, 0 means they are not. The two additional outputs show the computed key for each date, which you can use to see the actual month and year represented. For instance, key 202403 corresponds to March 2024. If the keys differ, you can tell at a glance which date is earlier by comparing the numeric keys.
Common Mistakes and Pitfalls
- Ignoring the year: Some people only compare the month number, which would incorrectly treat March 2023 and March 2024 as the same. Always include the year.
- Date format confusion: The calculator expects YYYY-MM-DD (ISO 8601). If you enter MM/DD/YYYY, the result will be wrong. Always use the ISO format.
- Leap day: February 29 exists only in leap years. The calculator handles it correctly as long as you enter a valid date; invalid dates like 2023-02-29 will cause an error.
- Time components: If your dates include time, the calculator ignores it. That is fine for month/year checks, but be aware that the day is still used to determine the month (e.g., 2024-01-31 23:59 is still January).
Limitations of the Formula
This formula only checks the calendar month and year. It does not tell you whether the dates are within the same fiscal year, same quarter, or same week. For those, you would need different calculations. Also, the formula assumes the Gregorian calendar, which is the standard in most of the world. If you work with other calendars (e.g., lunar or Hebrew), this check will not apply.
Another limitation: the key value (year×100+month) is not a continuous measure of time. For example, December 2024 (key 202412) and January 2025 (key 202501) are only 89 apart, but there is a full month between them. That is fine for equality checks, but do not use the key to calculate differences in months.
Alternative Methods
If you are working in a spreadsheet, you can achieve the same result with a formula like =TEXT(A1,"YYYY-MM")=TEXT(B1,"YYYY-MM") in Excel or Google Sheets. In programming languages, you can extract the year and month using built-in date functions and compare them. The calculator here provides a quick, no-code solution for a one-off check.
Frequently Asked Questions
Does this work for dates in different centuries?
Yes. The year is included in the key, so 1999-12-01 and 2099-12-01 will have keys 199912 and 209912, which are different. The calculator correctly returns 0.
What if I enter the dates in a different format?
The calculator expects YYYY-MM-DD. If you enter 03/15/2024, it will likely be interpreted as an invalid date. Always use the ISO format to avoid errors.
Can I use this to check if two dates are in the same quarter?
No. This calculator only checks month and year. For quarters, you would need to group months into sets of three (e.g., Jan–Mar, Apr–Jun) and compare those groups along with the year.
Does it handle leap years correctly?
Yes, as long as you enter a valid date. February 29, 2024 is a valid date, and the calculator will treat it as February 2024. February 29, 2023 is invalid and will cause an error.
Why does the output show 0 or 1 instead of “Yes” or “No”?
The calculator uses numeric output for simplicity. A 1 means the dates share the same month and year; 0 means they do not. The accompanying month/year keys help you see why.
Is there a way to compare only the month, ignoring the year?
Not with this calculator. If you need that, you would have to strip the year from each date and compare only the month numbers. That is a different check.
Related
Formula used
in d1 | First date | yyyy-mm-dd | 2024-03-15 | 0 in d2 | Second date | yyyy-mm-dd | 2024-03-20 | 0 out same | Same month and year? | - | (year(d1)*100+month(d1)) = (year(d2)*100+month(d2)) ? 1 : 0 | 0 out m1 | First month/year | - | year(d1)*100+month(d1) | 0 out m2 | Second month/year | - | year(d2)*100+month(d2) | 0
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.