0

I have the following design and I want to add six months to the start date on On-blur event but my code returns the finish date in millisecond format.

    function calDate() {
    var date1 = new Date(document.getElementById('txtstdate').value);
    document.getElementById("txtenddate").value = date1.setDate(date1.getDate()+30);

Current Design:-

Sardar Usama
  • 19,328
  • 9
  • 35
  • 57
Nimantha
  • 13
  • 4
  • This the code i have written to add 30 days to current date – Nimantha Jul 16 '16 at 17:57
  • 7
    Possible duplicate of [Javascript function to add X months to a date](http://stackoverflow.com/questions/2706125/javascript-function-to-add-x-months-to-a-date) – Iceman Jul 16 '16 at 18:07

2 Answers2

0

You need to use setMonth function here.

Use this as a reference: How to add months to a date in JavaScript?

Community
  • 1
  • 1
Object Manipulator
  • 8,644
  • 2
  • 10
  • 31
-1

It should work like this:

function calDate() {
    var date1 = new Date(document.getElementById('txtstdate').value);
    document.getElementById("txtenddate").value = parseInt(date1.getDate()) + 30;
}
Cameron
  • 1,029
  • 12
  • 23