I need to be able to add 1, 2 , 5 or 10 days to today's date using jQuery.
const date = new Date(); date. setDate(date. getDate() + 1); // ✅ 1 Day added console.
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.
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.
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))
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With