Using MONTH and EOMONTH functions in Excel - formula examples

The tutorial explains the nuts and bolts of Excel MONTH and EOMONTH functions. You will find an array of formula examples demonstrating how to extract month from date in Excel, get the first and last day of the month, convert month name to number and more.

In the previous article, we explored a variety of formulas to calculate weekdays. Today, we are going to operate on a bigger time unit and learn the functions that Microsoft Excel provides for months.

In this tutorial, you will learn:

Excel MONTH function - syntax and uses

Microsoft Excel provides a special MONTH function to extract a month from date, which returns the month number ranging from 1 (January) to 12 (December).

The MONTH function can be used in all versions of Excel 2016 - 2000 and its syntax is as simple as it can possibly be:

MONTH(serial_number)

Where serial_number is any valid date of the month you are trying to find.

For the correct work of Excel MONTH formulas, a date should be entered by using the DATE(year, month, day) function. For example, the formula =MONTH(DATE(2015,3,1)) returns 3 since DATE represents the 1st day of March, 2015.

Formulas like =MONTH("1-Mar-2015") also work fine, though problems may occur in more complex scenarios if dates are entered as text.

In practice, instead of specifying a date within the MONTH function, it's more convenient to refer to a cell with a date or supply a date returned by some other function. For example:

=MONTH(A1) - returns the month of a date in cell A1.

=MONTH(TODAY()) - returns the number of the current month.

At first sight, the Excel MONTH function may look plain. But look through the below examples and you will be amazed to know how many useful things it can actually do.

How to get month number from date in Excel

There are several ways to get month from date in Excel. Which one to choose depends on exactly what result you are trying to achieve.

MONTH function in Excel - get month number from date

This is the most obvious and easiest way to convert date to month in Excel. For example:

  • =MONTH(A2) - returns the month of a date in cell A2.
  • =MONTH(DATE(2015,4,15)) - returns 4 corresponding to April.
  • =MONTH("15-Apr-2015") - obviously, returns number 4 too.

TEXT function in Excel - extract month as a text string

An alternative way to get a month number from an Excel date is using the TEXT function:

  • =TEXT(A2, "m") - returns a month number without a leading zero, as 1 - 12.
  • =TEXT(A2,"mm") - returns a month number with a leading zero, as 01 - 12.

Please be very careful when using TEXT formulas, because they always return month numbers as text strings. So, if you plan to perform some further calculations or use the returned numbers in other formulas, you'd better stick with the Excel MONTH function.

The following screenshot demonstrates the results returned by all of the above formulas. Please notice the right alignment of numbers returned by the MONTH function (cells C2 and C3) as opposed to left-aligned text values returned by the TEXT functions (cells C4 and C5).
Using the MONTH function to extract a month number from a date

How to extract month name from date in Excel

In case you want to get a month name rather than a number, you use the TEXT function again, but with a different date code:

  • =TEXT(A2, "mmm") - returns an abbreviated month name, as Jan - Dec.
  • =TEXT(A2,"mmmm") - returns a full month name, as January - December.

TEXT formulas to get a month name from date in Excel

If you don't actually want to convert date to month in your Excel worksheet, you are just wish to display a month name only instead of the full date, then you don't want any formulas.

Select a cell(s) with dates, press Ctrl+1 to opent the Format Cells dialog. On the Number tab, select Custom and type either "mmm" or "mmmm" in the Type box to display abbreviated or full month names, respectively. In this case, your entries will remain fully functional Excel dates that you can use in calculations and other formulas. For more details about changing the date format, please see Creating a custom date format in Excel.
Displaying a month name instead of a date

How to convert month number to month name in Excel

Suppose, you have a list of numbers (1 through 12) in your Excel worksheet that you want to convert to month names. To do this, you can use any of the following formulas:

To return an abbreviated month name (Jan - Dec):

=TEXT(A2*28, "mmm")

=TEXT(DATE(2015, A2, 1), "mmm")

To return a full month name (January - December):

=TEXT(A2*28, "mmmm")

=TEXT(DATE(2015, A2, 1), "mmmm")

In all of the above formulas, A2 is a cell with a month number. And the only real difference between the formulas is the month codes:

  • "mmm" - 3-letter abbreviation of the month, such as Jan - Dec
  • "mmmm" - month spelled out completely
  • "mmmmm" - the first letter of the month name

Converting month number to month name in Excel

How these formulas work

When used together with month format codes such as "mmm" and "mmmm", Excel considers the number 1 as Day 1 in January 1900. Multiplying 1, 2, 3 etc. by 28, you are getting Days 28, 56, 84, etc. of the year 1900, which are in January, February, March, etc. The format code "mmm" or "mmmm" displays only the month name.

How to convert month name to number in Excel

There are two Excel functions that can help you convert month names to numbers - DATEVALUE and MONTH. Excel's DATEVALUE function converts a date stored as text to a serial number that Microsoft Excel recognizes as a date. And then, the MONTH function extracts a month number from that date.

The complete formula is as follows:

=MONTH(DATEVALUE(A2 & "1"))

Where A2 in a cell containing the month name you want to turn into a number (&"1" is added for the DATEVALUE function to understand it's a date).
A formula to convert month name to number in Excel

How to get the last day of month in Excel (EOMONTH function)

The EOMONTH function in Excel is used to return the last day of the month based on the specified start date. It has the following arguments, both of which are required:

EOMONTH(start_date, months)
  • Start_date - the starting date or a reference to a cell with the start date.
  • Months - the number of months before or after the start date. Use a positive value for future dates and negative value for past dates.

Here are a few EOMONTH formula examples:

=EOMONTH(A2, 1) - returns the last day of the month, one month after the date in cell A2.

=EOMONTH(A2, -1) - returns the last day of the month, one month before the date in cell A2.

Instead of a cell reference, you can hardcode a date in your EOMONTH formula. For example, both of the below formulas return the last day in April.

=EOMONTH("15-Apr-2015", 0)

=EOMONTH(DATE(2015,4,15), 0)

To return the last day of the current month, you use the TODAY() function in the first argument of your EOMONTH formula so that today's date is taken as the start date. And, you put 0 in the months argument because you don't want to change the month either way.

=EOMONTH(TODAY(), 0)

Note. Since the Excel EOMONTH function returns the serial number representing the date, you have to apply the date format to a cell(s) with your formulas. Please see How to change date format in Excel for the detailed steps.

And here are the results returned by the Excel EOMONTH formulas discussed above:
Excel EOMONTH formulas to return the last date of the month

If you want to calculate how many days are left till the end of the current month, you simply subtract the date returned by TODAY() from the date returned by EOMONTH and apply the General format to a cell:

=EOMONTH(TODAY(), 0)-TODAY()

How to find the first day of month in Excel

As you already know, Microsoft Excel provides just one function to return the last day of the month (EOMONTH). When it comes to the first day of the month, there is more than one way to get it.

Example 1. Get the 1st day of month by the month number

If you have the month number, then use a simple DATE formula like this:

=DATE(year, month number, 1)

For example, =DATE(2015, 4, 1) will return 1-Apr-15.

If your numbers are located in a certain column, say in column A, you can add a cell reference directly in the formula:

=DATE(2015, B2, 1)
A DATE formula to get the 1st day of month by the month number.

Example 2. Get the 1st day of month from a date

If you want to calculate the first day of the month based on a date, you can use the Excel DATE function again, but this time you will also need the MONTH function to extract the month number:

=DATE(year, MONTH(cell with the date), 1)

For example, the following formula will return the first day of the month based on the date in cell A2:

=DATE(2015,MONTH(A2),1)
Getting the 1st day of month from a date

Example 3. Find the first day of month based on the current date

When your calculations are based on today's date, use a liaison of the Excel EOMONTH and TODAY functions:

=EOMONTH(TODAY(),0) +1 - returns the 1st day of the following month.

As you remember, we already used a similar EOMONTH formula to get the last day of the current month. And now, you simply add 1 to that formula to get the first day of the next month.

In a similar manner, you can get the first day of the previous and current month:

=EOMONTH(TODAY(),-2) +1 - returns the 1st day of the previous month.

=EOMONTH(TODAY(),-1) +1 - returns the 1st day of the current month.

You could also use the Excel DATE function to handle this task, though the formulas would be a bit longer. For example, guess what the following formula does?

=DATE(YEAR(TODAY()), MONTH(TODAY()), 1)

Yep, it returns the first day of the current month.

And how do you force it to return the first day of the following or previous month? Hands down :) Just add or subtract 1 to/from the current month:

To return the first day of the following month:

=DATE(YEAR(TODAY()), MONTH(TODAY())+1, 1)

To return the first day of the previous month:

=DATE(YEAR(TODAY()), MONTH(TODAY())-1, 1)

How to calculate the number of days in a month

In Microsoft Excel, there exist a variety of functions to work with dates and times. However, it lacks a function for calculating the number of days in a given month. So, we'll need to make up for that omission with our own formulas.

Example 1. To get the number of days based on the month number

If you know the month number, the following DAY / DATE formula will return the number of days in that month:

=DAY(DATE(year, month number + 1, 1) -1)

In the above formula, the DATE function returns the first day of the following month, from which you subtract 1 to get the last day of the month you want. And then, the DAY function converts the date to a day number.

For example, the following formula returns the number of days in April (the 4th month in the year).

=DAY(DATE(2015, 4 +1, 1) -1)

Example 2. To get the number of days in a month based on date

If you don't know a month number but have any date within that month, you can use the YEAR and MONTH functions to extract the year and month number from the date. Just embed them in the DAY / DATE formula discussed in the above example, and it will tell you how many days a given month contains:

=DAY(DATE(YEAR(A2), MONTH(A2) +1, 1) -1)

Where A2 is cell with a date.

Alternatively, you can use a much simpler DAY / EOMONTH formula. As you remember, the Excel EOMONTH function returns the last day of the month, so you don't need any additional calculations:

=DAY(EOMONTH(A1, 0))

The following screenshot demonstrates the results returned by all of the formulas, and as you see they are identical:
Excel formulas to get the number of days in a month based on date

How to sum data by month in Excel

In a large table with lots of data, you may often need to get a sum of values for a given month. And this might be a problem if the data was not entered in chronological order.

The easiest solution is to add a helper column with a simple Excel MONTH formula that will convert dates to month numbers. Say, if your dates are in column A, you use =MONTH(A2).

And now, write down a list of numbers (from 1 to 12, or only those month numbers that are of interest to you) in an empty column, and sum values for each month using a SUMIF formula similar to this:

=SUMIF(C2:C15, E2, B2:B15)

Where E2 is the month number.

The following screenshot shows the result of the calculations:
A SUMIF formula to sum data by month in Excel

If you'd rather not add a helper column to your Excel sheet, no problem, you can do without it. A bit more trickier SUMPRODUCT function will work a treat:

=SUMPRODUCT((MONTH($A$2:$A$15)=$E2) * ($B$2:$B$15))

Where column A contains dates, column B contains the values to sum and E2 is the month number.

Note. Please keep in mind that both of the above solutions add up all values for a given month regardless of the year. So, if your Excel worksheet contains data for several years, all of it will be summed.

How to conditionally format dates based on month

Now that you know how to use the Excel MONTH and EOMONTH functions to perform various calculations in your worksheets, you may take a step further and improve the visual presentation. For this, we are going to use the capabilities of Excel conditional formatting for dates.

In addition to the examples provided in the above mentioned article, now I will show you how you can quickly highlight all cells or entire rows related to a certain month.

Example 1. Highlight dates within the current month

In the table from the previous example, suppose you want to highlight all rows with the current month dates.

First off, you extract the month numbers from dates in column A using the simplest =MONTH($A2) formula. And then, you compare those numbers with the current month returned by =MONTH(TODAY()). As a result, you have the following formula which returns TRUE if the months' numbers match, FALSE otherwise:

=MONTH($A2)=MONTH(TODAY())

Create an Excel conditional formatting rule based on this formula, and your result may resemble the screenshot below (the article was written in April, so all April dates are highlighted).
Highlighting dates within the current month

Example 2. Highlighting dates by month and day

And here's another challenge. Suppose you want to highlight the major holidays in your worksheet regardless of the year. Let's say Christmas and New Year days. How would you approach this task?

Simply use the Excel DAY function to extract the day of the month (1 - 31) and the MONTH function to get the month number, and then check if the DAY is equal to either 25 or 31, and if the MONTH is equal to 12:

=AND(OR(DAY($A2)=25, DAY($A2)=31), MONTH(A2)=12)
Highlighting dates by month and day

This is how the MONTH function in Excel works. It appears to be far more versatile than it looks, huh?

In a couple of the next posts, we are going to calculate weeks and years and hopefully you will learn a few more useful tricks. If you are interested in smaller time units, please check out the previous parts of our Excel Dates series (you will find the links below). I thank you for reading and hope to see you next week!

480 comments

  1. Hi,

    I am trying to work out a formula if one cell = January, then another cell =31/1/24, or if the cell = February, the other cell = 28/2/24 etc for each month. Is there a simple formula for this?

    1. Hello Thomas!
      The formula below will do the trick for you:

      =EOMONTH(DATE(2024,1,1), MONTH(DATEVALUE(A1&" 1"))-1)

      A1 & “ 1”: combines the text “January” with the number “1” to get the text string “January 1”.
      DATEVALUE(A1 & “ 1”): DATEVALUE function converts the text string “January 1” to a date.
      MONTH(DATEVALUE(A1 & “ 1”)): MONTH function extracts the month number from this date.
      The result is the month number for “January”, which is 1.
      EOMONTH function determines the last day of the month.

  2. Hello,
    I want to find out the date of the first Friday of certain stated month, and write it in spesific cell.
    For example, if first date of January stated on A1, and the date of first Friday will write in B1.
    if first date of Febuary stated on A1 the the first date of Friday will appear in B1.
    and so on
    TQ

  3. Greetings
    is it possible to use Excel to compile a list of how many Mondays, Tuesdays etc. the are for each month of a year.
    Thanks

    1. How to make automatic days of the month based on the first day of the month example 01/12/2024

      Date 01, Sunday, date 02, Monday etc. until December 31

  4. hi,
    i want to get the month
    exp: 15/03/2023 - 24/08/2024

  5. Hello,
    How to create a sequence of months in a certain period of time?
    I have a project in a period of 3 years starting from November, so I will make November the 1st month until November 3 years later in the 36th month

    1. Hi! Here is the guide that may be helpful to you: How to add / subtract months to date in Excel. You can create a date sequence using these instructions: Create a date sequence in Excel and auto fill date series.
      The formula might look something like the following:

      =EDATE(N1,SEQUENCE(36,1,0,1))
      or
      =EDATE(N1,ROW(A1:A36)-1)

      N1 - start date.
      Set the date cell to the date format that you want to use. Use these instructions: How to change Excel date format and create custom formatting.

      1. Hello,

        I have a shrinking year starting in November, so I will make November the 1st month until then the 48th month.

  6. Hi ,
    i have in excel e.g in cell A1 is Year 2024, cell A2 is January, cell B1 need to use formula to get previous year which is expected to have Year 2023, cell B2 is December.

    how do i use formula to get previous year if my month is December, it does not matter which year.
    if my month is in January, it should take current year.

    im not sure of the formula to use.

    1. Hi! To get the previous month's name, use the formula below:

      =TEXT(EDATE(DATE(A1,MONTH(1&A2),1),-1),"mmmm")

      To get the number of the month from its name, use the MONTH function. Use DATE function to create a date: the first day of this month. Use EDATE function to subtract one month from that date. Use TEXT function to get the name of the month from that date.
      Use IF function to subtract 1 year from a condition. For example:

      =IF(A2="January",A1-1,A1)

      Or use the YEAR function:

      =YEAR(EDATE(DATE(A1,MONTH(1&A2),1),-1))

      1. Hi, thanks. How do you get the previous year using formula? for e.g. if my month is December, is there a formula to get previous year? if my month is January, then it should get current year.
        so meaning by looking at the month - if it is December, then previous month, otherwise, it should get current month.

        1. Hi! The formula I sent to you was created based on the description you provided in your first request. However, as far as I can see from your second comment, your task is now different from the original one. You can change the name of the month in the formula. I have given you all the necessary links to understand how this formula works.

          1. Hi, I've made some changes and it works! Thanks again :)

        2. correction:

          so meaning by looking at the month - if it is December, then previous year, otherwise, it should get current year. apologies for confusion.

  7. how do you change the date format

  8. how to convert months from the previous year to the current year.
    example: April 15, 2022 to June 20, 2024 = 26 months

  9. Sir, I have prepared the formula to calculate exact number of days between two dates (including one day fraction which do not work well in datedif formula to calculate days). Can you confirm that my formula is valid:-
    SUM(IF(AND(A13=EOMONTH(A13,-1)+1,B13=EOMONTH(B13,0)),DAY(EOMONTH(A13,0))+1-DAY(A13)+DAY(B13)-DAY(EOMONTH(A13,0)))+IF(AND(A13EOMONTH(A13,-1)+1,B13=EOMONTH(B13,0)),DAY(EOMONTH(A13,0))+1-DAY(A13)+DAY(B13)-(DAY(EOMONTH(B13,0))))+(IF(AND(A13EOMONTH(A13,-1)+1,B13EOMONTH(B13,0)),IF(DAY(EOMONTH(A13,0))+1-DAY(A13)+DAY(B13)>DAY(EOMONTH(A13,0)),DAY(EOMONTH(A13,0))+1-DAY(A13)+DAY(B13)-DAY(EOMONTH(A13,0)),DAY(EOMONTH(A13,0))+1-DAY(A13)+DAY(B13))))+IF(AND(A13=EOMONTH(A13,-1)+1,B13EOMONTH(B13,0)),DAY(EOMONTH(A13,0))+1-DAY(A13)+DAY(B13)-(DAY(EOMONTH(A13,0)))))

    1. The following formula shall for divisible month of fraction days which are left in datedif(startmonth, endmonth,"md") formula

      =SUM(IF(AND((EOMONTH(A12,-1)+1)=A12,EOMONTH(B12,0)=B12),DAY(EOMONTH(B12,0)),0)+IF(AND((EOMONTH(A12,-1)+1)B12),DAY(EOMONTH(B12,0)),0)+IF(AND((EOMONTH(A12,-1)+1)<A12,EOMONTH(B12,0)B12),DAY(EOMONTH(B12,0)),0))

      1. Hi! I don't really understand what you want to achieve with this formula, but for two dates it returns the wrong number of days.

  10. Suppose I want to calculate the difference of year month and date e.g. take a start date 5.6.2020 and end date 8.7.2022. The result shown by the excel is 2 years 1 month and 3 days, if we use datedif(start date, end date,"y"), datedif(start date, end date,"ym") and datedif(start date, end date,"md") formula. But, exact answer is 2 years 1 month and 4 days. Similarly, we calculate difference above fomrula between the dates 5.7.2020 and 8.8.2022, the awnser shown by the excel is 2 years 1 months and 3 days. Whereas, the correct answer should be 2 years 1 months and 5 days. I do not know how to come out of this problem. As I have to calculate salary on the basis of these dates. Please help

    1. Hi! I have written many times that the date for example 8.7.2022 means the date and time 8.7.2022 00:00:00. You can see this by setting the cell containing the date to custom date and time format "d.mm.yyyy hh:mm:ss".
      Therefore, this day cannot be included in the calculation of the number of days between two dates.

  11. i want help with an if statement. so if the date is last day of month, to show true, other wise false. i want to do this for several dates

  12. Dear Mr.Alexander,

    below sheet i want to calculate in both ways in same time. by month and by Qtr. please give me suggestion..

    YR 2021 X Y X Jan mar
    QTR month typ AMT AMT Q1 Q2
    Q1 jan food 1.000 2.000 foodjanQ1
    Q1 feb food 1.000 2.000 foodfebQ1 Food 0
    Q1 mar food 1.000 2.000 foodmarQ1
    Q2 apr food 2.000 3.000 foodaprQ2
    Q2 may food 2.000 3.000 foodmayQ2
    Q2 jun food 2.000 3.000 foodjunQ2
    Q3 jul food 3.000 4.000 foodjulQ3
    Q3 aug food 3.000 4.000 foodaugQ3
    Q3 sep food 3.000 4.000 foodsepQ3
    Q4 oct food 4.000 5.000 foodoctQ4
    Q4 nov food 4.000 5.000 foodnovQ4
    Q4 dec food 4.000 5.000 fooddecQ4
    30.000 42.000

    Thanks

  13. Hi, I'm trying to find a formula to return the 15th of the next month, if the cell has a date range between 1st to 31st of the previous month. What is the best formula to use? Thank you!

    1. Hi! To get the date on the 15th of the next month, try this formula:

      =EOMONTH(A1,0)+15

      Please read the above article carefully.

  14. I am looking to create a table to calculate and monitor battery life. The user can input in cell C7 the expected battery life of a product in months (24 months). The surrounding cells are percentages of that and as such the outputs are in a # of months and # days.

    For example, I expect when no LEDs are on to get the battery life of 24 months.
    I expect when all LEDs are on that my expected battery life should be 1/10th of that, meaning 2 months and 12 days (rounded).

  15. Hi Alex

    Please I want to change the format of short month to long month on another column, which formular do I use?

    E.g I want Jan to return January but on another Column

  16. Hi
    Hope all will be fine.
    When I apply date format to text "10-06-2023", it converts it to 06-10-2023 or 06-Oct-2023. But I need the result 10-Jun-2023. How to sort it out?

      1. Thnx for the reply. But I have done everything to sort it out but in vain. Then I tried CSV and import process and finally resolved.

  17. Hi - I'm looking to calculate % of days that fall in each quarter based on a start and end date, counting the start date as a day in the quarter and in the total. For example: I have a start date of 3/26 and end date of 4/9. That's 6 days in Q1 (40%) and 9 days (60%) in Q2. Is there a formula I can use to output number of days in Q1 and number of days in Q2? Is there a formula I can use to calculate the % of total days that fall in a given quarter?

  18. Hi! I need to create a formula that inserts the number of the month (1-12) into a cell if the date falls between the 1st and the 15th of the month. If the date falls between the 16th and EOM, I need to put the number of the month (1-12) into another cell.

    Cells in Column A are used to calculate income that is received between the 1st and 15th.
    Cells in Column B are used to calculate income that is received between the 16th and EOM.

    These cells will be used in a formula to determine where to add income amounts on a different sheet within the workbook.

  19. used =TEXT(A5; "mmm") where A5 was a date formated as 2022-06-19 returned either 00 or =TEXT(A5; "mmm")

    I am presumably missing something obvious!

    1. Hi! I don't know what local date settings are used in your Windows. I assume that the date is written as text. To get the date, try these recommendations: How to convert text to date and number to date in Excel.
      You can extract the day, month and year from the text and create a date using the DATE function.

      =DATE(LEFT(A2,SEARCH("-",A2)-1),MID(A2,SEARCH("-",A2)+1,SEARCH("-",A2,SEARCH("-",A2)+1)-SEARCH("-",A2)-1),RIGHT(A2,LEN(A2)-SEARCH("-",A2,SEARCH("-",A2,1)+1)))

  20. Hi I need some help please.

    I need to get extract data from a table of every working day in month, but only that which falls on the last day of the month. The data set contains multiple years worth of data so need it specifically for each month of each year.
    Is this possible?

    Data looks like this:

    Date Value of transactions Number Of transactions Largest transaction
    04/01/2021 47 96 6
    05/01/2021 35 46 12

    So I would need the value of transactions for the last working day of every month for 2021, 2022, etc

    Thanks

Post a comment



Thank you for your comment!
When posting a question, please be very clear and concise. This will help us provide a quick and relevant solution to
your query. We cannot guarantee that we will answer every question, but we'll do our best :)