Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add number of days to today's date? [duplicate]

I need to be able to add 1, 2 , 5 or 10 days to today's date using jQuery.

like image 976
Linda725 Avatar asked Sep 29 '10 01:09

Linda725


People also ask

How can I add 1 day to current date?

const date = new Date(); date. setDate(date. getDate() + 1); // ✅ 1 Day added console.

How do you add days in date in react JS?

Adding days to current Date const current = new Date(); Now, we can add the required number of days to a current date using the combination of setDate() and getDate() methods.

How can I get today's date in this moment?

To get current date with Moment and JavaScript, we use the moment function without any arguments. const datetime = moment(); to call moment to get a moment object with the current date.


2 Answers

You can use JavaScript, no jQuery required:

var someDate = new Date(); var numberOfDaysToAdd = 6; var result = someDate.setDate(someDate.getDate() + numberOfDaysToAdd); console.log(new Date(result)) 
like image 53
p.campbell Avatar answered Sep 30 '22 04:09

p.campbell


This is for 5 days:

var myDate = new Date(new Date().getTime()+(5*24*60*60*1000)); 

You don't need JQuery, you can do it in JavaScript, Hope you get it.

like image 34
user3945851 Avatar answered Sep 30 '22 05:09

user3945851