The EOMONTH function is one of those little gems in Excel that can save you a lot of trouble. It's a simple function that does just one thing: given a date, it returns the last day of a month.
This may seem a little silly — how hard can it be to figure out the last day of a month? — but it's actually a bit tricky, since each month has a different numbers of days, and February changes in leap years.
Enter the EOMONTH function
EOMONTH takes two arguments: a start date, and months. Months represents the number of months to move in the future or past. So, for example, with May 12, 2017 in cell B5: