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:
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).
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.
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.
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
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).
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:
- 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:
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:
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)
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:
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)
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:
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:
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:
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).
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)
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!
470 comments
how to convert date 19.12.2016 to 19/12/2016
I was wondering if it would be possible to use the "Month" formula to conditionally format dates which are either one month or two months old? So for example, if the current month is February, I would want dates that fall between December to January to be highlighted. But I want this to go on for a continual basis, so that when I put in some dates next month, January and February will be highlighted. Is this possible with conditional formatting? Many Thanks.
When i subtract two dates like 1/Feb/2016-1/Jan/2016=31 days.
i want to know that these 31 days come in which month (For Example= Jan'15 month).
Please help to suggest any formula.
Hello Maria,
I have a date in a cell (6/12/14). I would like to be able to show just the year in another cell. If the date is before July 1 then the return would be 2014. If the date is after July 1 then the return would be 2015.
Thanks for any help you could offer.
Joe
how to get three letter month for example convert December into DEC.
Hello, Medusa,
You can use this formula in the Helper column to leave 3 first letters:
=LEFT(TRIM(A1), 3)
Is there a way to clean up How to sum data by month in Excel so I don't need a second 'month' column? And can this be modified to sort data by month and year, ie, multiple years data that is parsed into January , february, etc buckets by year, say a column for 2015 that shows Jan - Dec and another column for 2014 that does the same for Jan-Dec but extracts data from a multi-year column of data?
Hello, Pete,
Sorry, looks like it's not possible to accomplish this task without parsing data.
I was wondering how to create a formula so that I can see data from a particular month.
For example - For Budget review, we typically will need to see the previous month's data:
if Jan, show data in cell G4,
if Feb, show data in cell G5,
if Mar show data in cell G6,
if Apr, show data in cell G7,
if May, show data in cell G8,
if Jun, show data in cell G9,
if Jul, show data in cell G10,
if Aug, show data in cell G11,
if Sep, show data in cell G12,
if Oct, show data in cell G13,
if Nov, show data in cell G14,
if Dec, show data in cell G15
Hello, Todd,
I think this formula should work:
=IF(MONTH(A1)=1,G4,IF(MONTH(A1)=2,G5,IF(MONTH(A1)=3,G6,IF(MONTH(A1)=4,G7,IF(MONTH(A1)=5,G8,IF(MONTH(A1)=6,G9,IF(MONTH(A1)=7,G10,IF(MONTH(A1)=8,G11,IF(MONTH(A1)=9,G12,IF(MONTH(A1)=10,G13,IF(MONTH(A1)=11,G14,G15)))))))))))
credit date to payment date how to calculate day in the exel work sheet.
I used the formula "Datedif" both for Month and year, it's missed one Month or one Year. Eg. 01/Jan/2014 and 31/Dec/2014 the logical is 12 Months but the answer of the formula is 11 Months (Wrong).
One More example - Difference below two dated in months calculated with =Datedif , function is 47 as it has missed both the months ( starting and end )
1/5/2019 3/5/2015 47 ( 5th jan-2019 To 5th March 2015)
Please help - I want in my formula to include both the months at the time of calculation.
Actual expire date of cheque I want.
I have cheques eg.cheque issue date 29/03/2015 chque is valied for 6 months issue date to future six month how to calculate.
Thank you very much Svetlana, works very well
I am trying to convert a Month into the a date number.
eg If I write the Month October, I want to convert to the following 1/10/15
Hello Mark,
Excel formulas cannot convert a month to a date in the same cell. But if you enter October, say in cell A1, you can enter the following formula in some other cell to convert it to the date:
=DATE(YEAR(TODAY()), MONTH(DATEVALUE(A1& "1")), 1)
I need a formula which returns inception-to-date sum of a specified account code, such that this sum changes whenever a month is selected from a drop-down list. Need help!
I have days as number which will give difference between two dates...
For example : 01-03-2015 and 03-04-2015. I will get difference as 33 days.
Now to know this 33 days comes in which month... like 380 days comes in 13th month
(Year(Current Date)-year(previous date))*12+month(Current Date)
If you have the previous date in A1 and number of days as integer in A2
Then formula will be
=(Year(A1+A2)-Year(A1))*12+Month(A1+A2)
Hi, really interesting,
however also wanted to know if its possible to count how many dates occur in the next 60 days.
Have a list of certificate expiry dates, and want to know how many in column E expire in the next 60 days.
Is this possible within excel?
I've tried all of these;
=COUNTIF(E11:E1000,">"&DATE(YEAR(TODAY()),MONTH(TODAY())+2,DAY(TODAY())))
=COUNTIFS(E11:E1000,">"&"Today",E11:E1000,"<"&"Today"+60)
=COUNTIF(E11:E1000,August(TODAY())+2)
and none work/give me the correct answer. trialing the equations and know I have 4 within the next 60 days, each either give me 6 or 0.
Do you have any possible suggestions? Thanks
Hello, AC,
Please use the formula below:
=SUM((DAYS(E11:E1000,TODAY()) <= 60) * 1)
Note, this is an array formula. Press CTRL+SHIFT+ENTER to enter it.
Hi.
Im trying to autofill dates from a month..
example: if i fill the name of month: january.. then my 31 tables has to autofill the dates. those tables has to be connected with the name january..
i made something for now..
i put a datenumber example: 1-7-2015.. and the other tables autofills the date with +1 day for the next one...
but was wondering if i put the month name, will it change too. thx for help
Hello, Memo,
For us to be able to help you better, please send us the formula you use.
I have a similar problem to what is above. I want to autofill a column with the date number by referencing a column where I will just enter whatever months I want to be filled
Really appreciate the help
Hello. I have the sampe problem. would u mind to share the steps or formula ? thanks
Hi!
If "01.09.2015" is a text value, then replace "." with "/" first to convert it to a date. You can use the Replace All feature as demonstrated in Converting text strings with custom delimiters.
And then you can apply the mmm'yy format to the cell, see Creating custom date format for the detailed steps.
Hi, may I know how to convert the data below to month ?
01.09.2015
I want the answer in Sep'15
Many thanks.
=PROPER(TEXT(A2;"MMM"&"'"&"YY"))
A2 is the cell where the date is. For Office 2013 use ; in formula. For earlier office use ,
=PROPER(TEXT(DATE (2015;9;1);"MMM"&"'"&"YY"))
Hi...
U can tray this..
1st u have to convert into the date format to that the particular cell..follow the below ...
♦Press -alt+a+e (Text to columns) with select the cell
♦Then it should be in default mode or select ◘ Delimited - Next -Then remove all the check mark from all Delimited tab -then enter next- and select date in column data format range and select DMY - then enter Finish....
After all this your date formats will be change into 9/1/2015
then u can apply TEXT function to get your ans :-
9/1/2015 - =TEXT(select the sell,"mmmyy")
I hope u will get your answer ..
Thanks and cheers
Rajesh
Please just replace "." to "/" and than use =EOMONTH(A2,0)
when i entr any number in excel cell it will be changed into decimels like 5 is changed as 0.005, but when i put =and then put NUmber, it will not be changed