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,536
  • 9
  • 36
  • 58
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
Indrasis Datta
  • 8,692
  • 2
  • 14
  • 32
-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,049
  • 12
  • 24