How to calculate a date from date inputs using javascript? Here is my code:
<p>
Start date: <input id="start" name="start" placeholder="Start Date(mm/dd/yyyy)" type="date" />
</p>
<p>
End date: <input id="end" name="end" placeholder="End Date(mm/dd/yyyy)" type="date" />
</p>
I want to display a date by adding 17 months to the end date
Use following and add 17 months
var myDate = new Date();
myDate.setMonth( myDate.getMonth() + 17 );
alert(myDate);
Get the value of the end date with JQuery like this:
var endDate = $("#end").val();
Then turn it into a date object:
endDate = new Date(endDate);
You can then add 515 (365 for 12 months, and 300 for the extra 5 months approx.) days to the date like this:
endDate.setDate(endDate.getDate()+515);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.