Days in this month excel

Summary

To get the number of days in a given month from a date, you can use a formula based on the EOMONTH and DAY functions.

In the example shown, the formula in cell B5 is:

=DAY(EOMONTH(B5,0))

Generic formula

Explanation 

The DAY function returns the day component of a date. The EOMONTH function returns the last day of the month for a given date. So, in this formula EOMONTH first returns a date corresponding to the last day of the month, and then DAY returns the date value for that date.

By definition, the value returned by DAY is always equal to the number of days in the month, since the date supplied to DAY is always the last day.

Dave Bruns Profile Picture

AuthorMicrosoft Most Valuable Professional Award

Dave Bruns

Hi — I’m Dave Bruns, and I run Exceljet with my wife, Lisa. Our goal is to help you work faster in Excel. We create short videos, and clear examples of formulas, functions, pivot tables, conditional formatting, and charts.

Great site — amazingly clear but with a lot of depth in terms of the explanations.

Get Training

Quick, clean, and to the point training

Learn Excel with high quality video training. Our videos are quick, clean, and to the point, so you can learn Excel in less time, and easily review key topics when needed. Each video comes with its own practice worksheet.

View Paid Training & Bundles

Help us improve Exceljet

Home / Excel Formulas / How to Get Total Days in Month in Excel

Sometimes you need to calculate the total number of days in a month to use in further calculations. It happens specifically when you work on templates and dashboards. So today, let me show you a simple formula that can do this for you.

To calculate the number of days in a given month from a date, we need to use a formula based on EOMONTH and DAY.

=DAY(EOMONTH(A2,0))
get total number in month using day eomonth functions

How this Formula Works

As you see this formula is a combination of two functions. We have EOMONTH which is covered within DAY.

  1. First, when you refer to a date and “0” in EOMONTH it returns the last date of that month. Here the date is on cell A2.
  2. Second, the DAY function returns the day from the last day returned by EOMONTH.

The day of the month’s last day is always the total number of days in a month. From 31-Mar-2017, it returns 31 which is the total number of days in March month.

Dynamic Formula

Let’s you want to get the total days in a month for the current month and you want this formula to return it automatically every time the month changes.

The formula will be:

=DAY(EOMONTH(TODAY(),0))

In this formula, instead of referring to a date, we have referred to TODAY in EOMONTH which returns the current date and then EOMONTH returns the last date from the current date’s month.

In the end, DAY returns the day number and gets the total number of days for the current month.

Get Days in Month using Month Name

Let’s say you have entered a month’s name in a cell not a proper date and now you want to calculate the total number of days from this month. The formula will be:

=DAY(EOMONTH(DATEVALUE("01-"&A2&"-"&YEAR(TODAY())),0))
get total number in month using month name

This formula creates the first day’s date of the month you have mentioned and then EOMONTH returns the last date and DAY returns the last day which is the total number of days in a month. You can use the month’s name both in short form and in long form.

Return to Excel Formulas List

Download Example Workbook

Download the example workbook

This tutorial will teach you how to calculate the number of days in a month using Excel or Google Sheets.

Days in month Main

Calculate Number of Days in a Month

Last Day of Month

The first step to calculating the number of days in a month is to calculate the last day of the month. We can easily do this with the EOMONTH Function:

=EOMONTH(B3,C3)

Last Day on the Month

Enter the date into the EOMONTH Function and “0” to calculate the last day of the current month (use -1 to calculate the last day of the previous month).

Calculate Day

Next, use the DAY Function to extract the day number of the last day of the month:

=DAY(EOMONTH(B3,0))

Calculate Day

This will display the number of days in the month.

Number of Days in Current Month

Use the previous formula along with the TODAY Function to calculate the last day of the current month:

=DAY(EOMONTH(TODAY(),0))

No Of Days Current Month

Number of Days in Previous Month

As mentioned above, we set the second argument of the EOMONTH Function to -1 to calculate the last day of the previous month:

=DAY(EOMONTH(TODAY(),-1))

NO of Days in Previous Month

Days in Month – Google Sheets

There formulas work exactly the same in Google Sheets as in Excel:

Days in month Google sheet

Skip to content

Exceldome

Exceldome

This tutorial shows how to return the number of days in a current month using an Excel formula or VBA

Example: Return number of days in a current month

Return number of days in a current month

METHOD 1. Return number of days in a current month using Excel formula

EXCEL

This formula uses a combination of Excel DAY, EOMONTH and NOW functions to calculate the number of days that are in a current month. Using the NOW function inside the EOMONTH function, with the months criteria of 0, this part of the formula will return the last day in the current month, in date format. Then using the DAY function the formula will extract only the day from the date which would be the last day in the current month.

METHOD 1. Return number of days in a current month using VBA

VBA

Sub Days_in_a_Current_Month()

‘declare a variable
Dim ws As Worksheet

Set ws = Worksheets(«Analysis»)

‘return the number of days in a current month
ws.Range(«D5») = Day(Application.WorksheetFunction.EoMonth(Now, 0))

End Sub

ADJUSTABLE PARAMETERS
Output Range: Select the output range by changing the cell reference («D5») in the VBA code.

Explanation about how to extract the number of days in a current month

EXPLANATION

EXPLANATION

This tutorial shows how to return the number of days in a current month through the use of an Excel formula or VBA.

Both the Excel formula and VBA methods make use of the DAY, EOMONTH and NOW functions to return the number of days in the current month.

FORMULA
=DAY(EOMONTH(NOW(),0))

Related Topic Description Related Topic and Description
Return number of days in a month How to return the number of days in a specific month using Excel and VBA
Return previous month based on current month How to return the previous month based on the current month using Excel and VBA methods
Return next month based on current month How to return the next month based on the current month using Excel and VBA
Difference in months between two dates How to calculate the difference in months between two dates using Excel and VBA methods
Related Functions Description Related Functions and Description
DAY Function The Excel DAY function returns the day from a specified date
NOW Function The Excel NOW function returns the current date and time

Excel for Microsoft 365 Excel for Microsoft 365 for Mac Excel for the web Excel 2021 Excel 2021 for Mac Excel 2019 Excel 2019 for Mac Excel 2016 Excel 2016 for Mac Excel 2013 Excel 2010 Excel 2007 Excel for Mac 2011 Excel Starter 2010 More…Less

Use Excel’s DATE function when you need to take three separate values and combine them to form a date.

The DATE function returns the sequential serial number that represents a particular date.

Syntax: DATE(year,month,day)

The DATE function syntax has the following arguments:

  • Year    Required. The value of the year argument can include one to four digits. Excel interprets the year argument according to the date system your computer is using. By default, Microsoft Excel for Windows uses the 1900 date system, which means the first date is January 1, 1900.

    Tip: Use four digits for the year argument to prevent unwanted results. For example, «07» could mean «1907» or «2007.» Four digit years prevent confusion.

    • If year is between 0 (zero) and 1899 (inclusive), Excel adds that value to 1900 to calculate the year. For example, DATE(108,1,2) returns January 2, 2008 (1900+108).

    • If year is between 1900 and 9999 (inclusive), Excel uses that value as the year. For example, DATE(2008,1,2) returns January 2, 2008.

    • If year is less than 0 or is 10000 or greater, Excel returns the #NUM! error value.

  • Month    Required. A positive or negative integer representing the month of the year from 1 to 12 (January to December).

    • If month is greater than 12, month adds that number of months to the first month in the year specified. For example, DATE(2008,14,2) returns the serial number representing February 2, 2009.

    • If month is less than 1, month subtracts the magnitude of that number of months, plus 1, from the first month in the year specified. For example, DATE(2008,-3,2) returns the serial number representing September 2, 2007.

  • Day    Required. A positive or negative integer representing the day of the month from 1 to 31.

    • If day is greater than the number of days in the month specified, day adds that number of days to the first day in the month. For example, DATE(2008,1,35) returns the serial number representing February 4, 2008.

    • If day is less than 1, day subtracts the magnitude that number of days, plus one, from the first day of the month specified. For example, DATE(2008,1,-15) returns the serial number representing December 16, 2007.

Note: Excel stores dates as sequential serial numbers so that they can be used in calculations. January 1, 1900 is serial number 1, and January 1, 2008 is serial number 39448 because it is 39,447 days after January 1, 1900. You will need to change the number format (Format Cells) in order to display a proper date.

DATE function example 1

Syntax: DATE(year,month,day)

For example: =DATE(C2,A2,B2) combines the year from cell C2, the month from cell A2, and the day from cell B2 and puts them into one cell as a date. The example below shows the final result in cell D2.

DATE function Example 2

Need to insert dates without a formula? No problem. You can insert the current date and time in a cell, or you can insert a date that gets updated. You can also fill data automatically in worksheet cells.

  1. Right-click the cell(s) you want to change. On a Mac, Ctrl-click the cells.

  2. On the Home tab click Format > Format Cells or press Ctrl+1 (Command+1 on a Mac).

  3. 3. Choose the Locale (location) and Date format you want.

  4. For more information on formatting dates, see Format a date the way you want.

    Format a cell as a date

You can use the DATE function to create a date that is based on another cell’s date. For example, you can use the YEAR, MONTH, and DAY functions to create an anniversary date that’s based on another cell. Let’s say an employee’s first day at work is 10/1/2016; the DATE function can be used to establish his fifth year anniversary date:

Calculate a date based on another date

  1. The DATE function creates a date.

    =DATE(YEAR(C2)+5,MONTH(C2),DAY(C2))

  2. The YEAR function looks at cell C2 and extracts «2012».

  3. Then, «+5» adds 5 years, and establishes «2017» as the anniversary year in cell D2.

  4. The MONTH function extracts the «3» from C2. This establishes «3» as the month in cell D2.

  5. The DAY function extracts «14» from C2. This establishes «14» as the day in cell D2.

If you open a file that came from another program, Excel will try to recognize dates within the data. But sometimes the dates aren’t recognizable. This is may be because the numbers don’t resemble a typical date, or because the data is formatted as text. If this is the case, you can use the DATE function to convert the information into dates. For example, in the following illustration, cell C2 contains a date that is in the format: YYYYMMDD. It is also formatted as text. To convert it into a date, the DATE function was used in conjunction with the LEFT, MID, and RIGHT functions.

Convert text strings and numbers into dates

  1. The DATE function creates a date.

    =DATE(LEFT(C2,4),MID(C2,5,2),RIGHT(C2,2))

  2. The LEFT function looks at cell C2 and takes the first 4 characters from the left. This establishes “2014” as the year of the converted date in cell D2.

  3. The MID function looks at cell C2. It starts at the 5th character, and then takes 2 characters to the right. This establishes “03” as the month of the converted date in cell D2. Because the formatting of D2 set to Date, the “0” isn’t included in the final result.

  4. The RIGHT function looks at cell C2 and takes the first 2 characters starting from the very right and moving left. This establishes “14” as the day of the date in D2.

To increase or decrease a date by a certain number of days, simply add or subtract the number of days to the value or cell reference containing the date.

In the example below, cell A5 contains the date that we want to increase and decrease by 7 days (the value in C5).

Increase or decrease a date by a certain number of days

See Also

Add or subtract dates

Insert the current date and time in a cell

Fill data automatically in worksheet cells

YEAR function

MONTH function

DAY function

TODAY function

DATEVALUE function

Date and time functions (reference)

All Excel functions (by category)

All Excel functions (alphabetical)

Need more help?

Понравилась статья? Поделить с друзьями:
  • Days from today excel
  • Days and weeks excel
  • Days and hours in excel
  • Day word search puzzles
  • Day trip one word