How to add Number of Days to Date in Javascript.

Java Script Code snippet :-


$(function(){
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth()+1; //January is 0!
var yyyy = today.getFullYear();

if(dd<10) {
dd='0'+dd
}

if(mm<10) {
mm='0'+mm
}

todayDate = mm+'/'+dd+'/'+yyyy;
var NewDate=AddDays(todayDate,10); //Calling method
document.write(NewDate);
});

function AddDays(jsDate,iNoOfDays){
var thisUTC = jsDate.getTimezoneOffset();
jsDate.setTime(jsDate.getTime() + iNoOfDays * 86400000);
if (thisUTC != jsDate.getTimezoneOffset()) {
jsDate.setTime(jsDate.getTime() + (jsDate.getTimezoneOffset() - thisUTC) * 60000);
}

return (jsDate);
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s