Javascript date increment

I want to set a date textbox (in dd / mm / yyyy format) 14 days ahead of the current date in javascript. can anyone help me on this?

+2


a source to share


4 answers


This should do it:

var myDate=new Date();
myDate.setDate(myDate.getDate()+14);

      



then

document.getElementById(YOUR_TEXTBOX_ID).value = myDate.getDate() + "/" + 
  (myDate.getMonth() + 1) + "/" + myDate.getFullYear();

      

+9


a source


Date.js is a handy script for all kinds of JavaScript date manipulation. I have used it to create many date based interfaces including calendar controls.



0


a source


As Deodeus suggested, use Date.js:

var myDate = Date.today().add(14).days();
document.getElementById('mytextbox').value = myDate.toString('dd/MM/yyyy');

      

0


a source


Below is a function to increment date by one day in javascript.

function IncrementDate(date) {         
     var tempDate = new Date(date);
        tempDate.setDate(tempDate.getDate() + 1);
        return tempDate;
} 

      

Function call ...

var currentDate = new Date();
var IncrementedDate =  IncrementDate(currentDate);

      

0


a source







All Articles