0
    <code>
    var d2 =  $('#interval').val();
    var new_date = new Date(get_start_date); 
    new_date.setDate(new_date.getDate() + d2);
    var dd = new_date.getDate();
    var mm = new_date.getMonth() + 1;
    var y = new_date.getFullYear();
    var endDate = y + '-' + mm + '-' + dd;
    </code>

assuming d2 = 5

when im adding 5 dates to my current date, its not returning exact answer instead its adding months it becomes 2017-09-09 but when i just do this new_date.setDate(new_date.getDate() + 5) it gives me the correct output.

3
  • try var d2 = Number($('#interval').val()) Commented Apr 13, 2017 at 7:05
  • are you sure you are getting right value of d2? It gives you string not number, just parse it as a number Commented Apr 13, 2017 at 7:07
  • @gurvinder372 that did the trick! Thank u very much! Commented Apr 13, 2017 at 7:10

2 Answers 2

1

Just parse you d2 as an integer

var d2 = parseInt($('#interval').val(),10);

Sign up to request clarification or add additional context in comments.

Comments

0

u can only use this arguments new Date() new Date(milliseconds) new Date(dateString) new Date(year, month, day, hours, minutes, seconds, milliseconds)

get_start_date is invailid ;)

var new_date = new Date(get_start_date);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.