Month Number from Name: Quick Conversion Guide
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 converts a month name (like “January” or “Jan”) into its corresponding month number (1-12), and optionally the reverse. You enter the month name, and you get back the month number, along with the number of days in that month and its position in the year. It handles full names, three-letter abbreviations, and common case variations.
Formula
The conversion uses a simple lookup table. Each month name (and its common abbreviation) is mapped to an integer from 1 to 12. The formula is:
Month Number = Lookup(Month Name)
Where the lookup table is:
- January (Jan) → 1
- February (Feb) → 2
- March (Mar) → 3
- April (Apr) → 4
- May → 5
- June (Jun) → 6
- July (Jul) → 7
- August (Aug) → 8
- September (Sep, Sept) → 9
- October (Oct) → 10
- November (Nov) → 11
- December (Dec) → 12
The calculator also returns the number of days in that month (using 28 for February, ignoring leap years).
Worked Example
Using the default input January:
- Identify the month: January.
- Look up January in the table: January → 1.
- So the month number is 1.
- Days in January: 31 (since January is in the 31-day group).
The calculator displays: Month number: 1, Days in month: 31.
Why Convert Month Names to Numbers?
People often need this conversion for data entry, sorting, or programming. For example, if you have a list of birthdays written as “March 15” and you want to sort them chronologically, converting the month name to a number (3) makes sorting trivial. Spreadsheets and databases store dates as numbers (or date serials), so converting a month name to a number is a common first step in cleaning up text data. It’s also useful when writing formulas in Excel or Google Sheets, where functions like MONTH() expect a date, but you only have the month name as text.
Common Mistakes and How to Avoid Them
- Case sensitivity: Month names are often capitalized (January), but not always. The calculator treats “january”, “January”, and “JANUARY” the same. If you are doing this manually, always use lower case or a case-insensitive comparison.
- Abbreviations: “Sept” is sometimes used instead of “Sep”. The calculator accepts both. If you are writing code, remember to handle both.
- Leap years: February has 28 days in a common year and 29 in a leap year. The calculator returns 28, which is the standard for non-leap years. If you need the exact days for a specific year, you must account for leap years (divisible by 4, except century years not divisible by 400).
- Invalid names: If you type “Frebruary” or “March”, the calculator returns 0, indicating an invalid month. Always validate input.
How to Do It in Excel, Google Sheets, and Python
If you want to convert a month name to a number in a spreadsheet, you can use the MATCH function. For example, if cell A1 contains “March”, the formula =MATCH(A1, {"January","February","March","April","May","June","July","August","September","October","November","December"}, 0) returns 3. In Python, you can use a dictionary: month_num = {'january':1, 'february':2, ...} and then look up the lowercase name. These methods give you the same result as this calculator.
Month Names in Other Languages
This calculator only handles English month names. If you are working with Spanish (enero, febrero), French (janvier, février), or other languages, you will need a different lookup table. The logic is the same, but the names differ. For example, in Spanish, “enero” is 1, “febrero” is 2, etc. The same conversion principle applies.
Frequently Asked Questions
What is the month number for September?
September is the 9th month of the year. The abbreviation is Sep (or Sept). So the month number is 9.
How do I convert a month number back to a name?
You can use the reverse lookup: 1 = January, 2 = February, … 12 = December. In Excel, you can use =TEXT(DATE(2025, A1, 1), "mmmm") to get the full name. In Python, you can use a list: months = ['January', 'February', ...] and index with the number minus 1.
Why is February sometimes 29 days?
February has 29 days in a leap year, which occurs every 4 years (with exceptions for century years not divisible by 400). This is to keep the calendar aligned with the Earth’s orbit around the sun. The calculator returns 28 for simplicity, but you should adjust for leap years when needed.
Can I use this calculator for abbreviated month names?
Yes, the calculator accepts the standard three-letter abbreviations (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec) as well as the full names. It also accepts “Sept” for September.
What if I type a month name in lowercase?
The calculator is case-insensitive, so “january”, “January”, and “JANUARY” all work. If you are doing this manually, always convert to lowercase first to avoid errors.
How do I get the month number from a date in Excel?
If you have a full date, use the MONTH() function. For example, =MONTH(A1) returns the month number of the date in cell A1. This is different from converting a month name, but it gives the same result.
Related
Formula used
in name | Month name | - | January | 0 out num | Month number | - | (name matches "january" or "jan") ? 1 : (name matches "february" or "feb") ? 2 : (name matches "march" or "mar") ? 3 : (name matches "april" or "apr") ? 4 : (name matches "may") ? 5 : (name matches "june" or "jun") ? 6 : (name matches "july" or "jul") ? 7 : (name matches "august" or "aug") ? 8 : (name matches "september" or "sep" or "sept") ? 9 : (name matches "october" or "oct") ? 10 : (name matches "november" or "nov") ? 11 : (name matches "december" or "dec") ? 12 : 0 | 0 out days | Days in month | - | ((num == 1) or (num == 3) or (num == 5) or (num == 7) or (num == 8) or (num == 10) or (num == 12)) ? 31 : ((num == 4) or (num == 6) or (num == 9) or (num == 11)) ? 30 : (num == 2) ? 28 : 0 | 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.