Sometimes we need to get an end-of-month date to use as a completion date, a due date, as a target date, or sometimes we need it to calculate the days between two dates.
Without any effort, we can easily add it manually, but there are some formulas that can help us to calculate it.
The best way to calculate the last date of the month is by using the EOMONTH Function. But apart from this, you can also use other methods (VBA).
Using a formula or any other dynamic method has the benefit that we don’t need to calculate it again and again. Today, in this post, I’d like to share with you 3 simple and dynamic ways to get the end of the month date in Excel.
So let’s get started and please download this same file from here to follow along.
Get the Last Day of the Month using EOMONTH Function
EOMONTH is my favorite function to calculate the last day of a month. This function is specifically designed for these kinds of calculations.
All you have to do is just specify a date current date, and the number of months you want to calculate the last date before and after the start date. Here is the syntax:
In this syntax, the start date will be the current date and months will be a number that represents the number of months forward or backward.
End Date of the Same Month
Let’s say, you have the date “06-Feb-2017” and you want to get the last day of “Feb”. In this case, the formulas you need to use are:
In the above example, when you use EOMONTH, has returned 28-Feb-2017 which is the last date of the Feb month.
How does it work: Here, you have used “0” for the number argument because the start date you have used is of Feb month and you won’t have the last day of the same month. When you use “0” it will simply return the last date for the same month for which you have the start date.
To create a dynamic formula you can use the TODAY Function in the
End Date of the Future Month
Now, let’s say, from the same date you want to get the last day of “Apr”. In this case, the formulas you need to use are:
In the above example, the formula has returned 30-Apr-2017 which is the last date of the Apr month.
How does it work
Here, you have used “2” for the number argument and the start date you have used is of Feb month. Now, if you look, Apr is exactly 2 months after Feb so that’s why it has returned 30-Apr-2017.
End Date of the Previous Month
And, if you want to get the last date of a previous month you can use a negative number for that. Let’s say you want the last day of Jan. So, the formula you need to use:
In the above example, the formula has returned 31-Jan-2017 which is the last date of the Jan month.
How does it work: Here, you have used “-1” for the number argument and Jan is exactly 1 month before Feb.
DATE Function to Get Month’s Last Date
DATE Function is another approach to getting the last day in excel. The date function helps you to create a valid excel date by specifying the year, month, and day. Here is the syntax:
As I have mentioned, in the date function, you need to enter the year, month, and day, and it returns a valid date according to that. Now, there is a small trick that you can do with day argument.
And, if you want to calculate the last day of the current month the formula will be:
=DATE(CurrentYear,CurrentMonth + 1,0)
Or, if you just have a date to refer then the formula will be:
Get Last Day with a UDF
Function LastD(Optional sd As Date = 0) As Date If sd = 0 Then sd = VBA.DateLastD = VBA.DateSerial(VBA.Year(sd), VBA.Month(sd) + 1, 0) End Function
In your worksheet, type “=LastD(” and insert the date for the month or refer to a cell. And, if you want the last day of the current month then simply left it blank using brackets.
As I said, the month’s last day can be helpful for you while calculating target dates, due dates, or completion dates. And, now we have three different ways to get it.
If you use EOMONTH then it’s really easy to create a dynamic formula that can help you to date for past or future months and I think it’s the best way to do it.
I hope you found it useful and it will help you take your skills to the whole next level.
Now tell me one thing. Which one is your favorite method above all? Or, do you have a different method? Please share with me in the comment box, I would love to hear from you. And don’t forget to share it with your friends.