XL: How to Calculate the Number of Days in a Month (214313)
The information in this article applies to:
- Microsoft Excel 2000
- Microsoft Excel 2002
- Microsoft Excel 97 for Windows
- Microsoft Excel 2001 for Mac
- Microsoft Excel 98 Macintosh Edition
This article was previously published under Q214313 SUMMARY
In Microsoft Excel, you can use date functions to calculate the number
of days in a month. For example, you can use the following formula to
return the number of days in a month, based on a given starting date
=DAY(DATE(YEAR(The_Date),MONTH(The_Date)+1,0))
where The_Date is the starting date.
This formula works by finding the "zeroth" day of the month after
The_Date.
Because there is no "zeroth" day of any month, this date is interpreted as
the last day of the month containing The_Date. The DAY function then converts this date into a day number.
Or, to calculate the number of days in a month, given the month and year,
use the following function
=DAY(DATE(my_year,my_month+1,1)-1)
where my_month is the month for which you want to return the number of days, and my_year is the year. This function calculates the first day of the next month and subtracts 1, which equals the last day of the current month. The DAY function then gives you the day of the month.
REFERENCESFor more information about functions, click Microsoft Excel Help on the
Help menu, type about using functions to calculate values in the Office Assistant or
the Answer Wizard, and then click Search to view the topics
returned.
Modification Type: | Major | Last Reviewed: | 5/28/2003 |
---|
Keywords: | kbhowto KB214313 |
---|
|