I have an input type="date" and I'm trying to set the min number to today and the max number to 180 days from now (including/excluding today, doesn't matter at this moment). 

I can get today and set it as the min. That's fine.

When I try to set the max as 180, the function is returning non-existent dates, such as February 31st. According to <https://www.convertunits.com/dates/daysfromnow/180>, 180 days from today (September 03, 2019) would be March 1st, 2020. What in my code is calculating roughly the correct date, but allowing non-existant dates?

Note: if I change it to 181 days (so 180 days after today) then it's fine, but it won't be fine next year. When the date doesn't exist, it doesn't throw any errors, it just allows users to select any future date they want.

```
function OneHundredEightDaysAway() {
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1; //Jan = 0
var yyyy = today.getFullYear();

var date = new Date(yyyy, mm, dd);
var newdate = new Date(date);
newdate.setDate(newdate.getDate() + 180); //180 days in the future
var nd = new Date(newdate);

var DD = nd.getDate();
var MM = nd.getMonth();
var YYYY = today.getFullYear();

if (DD < 10) {
    DD = '0' + DD
}
if (MM < 10) {
    MM = '0' + MM
}

var maxStart = YYYY + "-" + MM + "-" + DD;

return maxStart;
}

```