1

I am printing date using datepicker this way:

$(".final-date").text($.datepicker.formatDate('dd.mm.yy', new Date()));

I am using it within my loan calculator. How can i add days to a current date? e.g. 17.01.2016, but in my calculator i choose loan period for 10 days, so it should be 27.01.2016

Alexander Kim
  • 17,304
  • 23
  • 100
  • 157
  • Will this not suffice for what you're looking for? If I've understood it correctly, you simply want to add 10 days to the current value that you have?\http://stackoverflow.com/questions/563406/add-days-to-datetime – Jak Hammond Jan 17 '16 at 12:03
  • Thanks, checking now. That's it! Post an answer. – Alexander Kim Jan 17 '16 at 12:12

1 Answers1

1

this should give you the offset date:

new Date(new Date().valueOf() + 1000*60*60*24*days); 

so your code would probably become:

$(".final-date").text($.datepicker.formatDate('dd.mm.yy', new Date(new Date().valueOf() + 1000*60*60*24*10);));

or maybe more legibly:

var loanPeriodDays = 10;
var dayInMillis = 1000*60*60*24;
var loadEndDate = new Date(new Date().valueOf() + dayInMillis*loanPeriodDays);
$(".final-date").text($.datepicker.formatDate('dd.mm.yy', loadEndDate));
ptrk
  • 1,800
  • 1
  • 15
  • 24