date = new Date('2013-02-11');
next_date = new Date(date.setDate(date.getDate() + 1));
here's a demo http://jsfiddle.net/MEptb/
Answer from Sanjay Kamaruddin on Stack Overflow Top answer 1 of 5
4
date = new Date('2013-02-11');
next_date = new Date(date.setDate(date.getDate() + 1));
here's a demo http://jsfiddle.net/MEptb/
2 of 5
4
Something like this :
var date = new Date('2013-02-11');
/* Add nr of days*/
date.setDate(date.getDate() + 1);
alert(date.toString());
I hope it helps.
MDN Web Docs
developer.mozilla.org โบ en-US โบ docs โบ Web โบ JavaScript โบ Reference โบ Global_Objects โบ Date
Date - JavaScript | MDN
YYYY is the year, with four digits (0000 to 9999), or as an expanded year of + or - followed by six digits. The sign is required for expanded years. -000000 is explicitly disallowed as a valid year. MM is the month, with two digits (01 to 12). Defaults to 01. DD is the day of the month, with two digits (01 to 31).
Videos
How to add days to current Date using JavaScript - YouTube
01:33
How to add days to a JavaScript date - YouTube
09:14
How to add days to date using Javascript - YouTube
02:02
Mastering JavaScript Dates: How to Add 7 Days to a Date - YouTube
How to add days to a date in JavaScript? . . . . . #javascript ...
01:47
How to Easily Add a Day to the Current Date in JavaScript - YouTube
Futurestud.io
futurestud.io โบ tutorials โบ add-days-to-a-date-in-javascript-or-node-js
Add Days to a Date in JavaScript or Node.js
This tutorial shows you how to add days to a date in JavaScript.
Day.js
day.js.org โบ docs โบ en โบ display โบ format
Format ยท Day.js
dayjs().format() // current date in ISO8601, without fraction seconds e.g. '2020-04-02T08:02:17-05:00' dayjs('2019-01-25').format('[YYYYescape] YYYY-MM-DDTHH:mm:ssZ[Z]') // 'YYYYescape 2019-01-25T00:00:00-02:00Z' dayjs('2019-01-25').format('DD/MM/YYYY') // '25/01/2019'
Top answer 1 of 15
7
Extending prototype in javascript may not be a good idea, especially in professional codebases.
What you want to do is extend the native Date class:
class MyCustomDate extends Date {
addDays(days) {
const date = new MyCustomDate(this.valueOf());
date.setDate(date.getDate() + days);
return date;
}
}
const today = new MyCustomDate();
const nextWeek = today.addDays(7)
console.log(nextWeek)
This way, if one day Javascript implements a native addDays method, you won't break anything.
2 of 15
6
I use something like:
new Date(dateObject.getTime() + amountOfDays * 24 * 60 * 60 * 1000)
Works with day saving time:
new Date(new Date(2014, 2, 29, 20, 0, 0).getTime() + 1 * 24 * 60 * 60 * 1000)
Works with new year:
new Date(new Date(2014, 11, 31, 20, 0, 0).getTime() + 1 * 24 * 60 * 60 * 1000)
It can be parametrized:
function DateAdd(source, amount, step) {
var factor = 1;
if (step == "day") factor = 24 * 60 * 60 * 1000;
else if (step == "hour") factor = 60 * 60 * 1000;
...
new Date(source.getTime() + amount * factor);
}
Acrobatusers
answers.acrobatusers.com โบ Add-days-date-European-dd-mm-yyyy-q122650.aspx
Add days to date (European dd/mm/yyyy) (JavaScript)
*/ /* 24 hours / day; 60 min / ... new Date(num); /* Put the input date plus 1 days using util.printd into InputDate7 */ this.getField("InputDate7").value =util.printd("dd/mm/yyyy", d2); /* Add one day to Date1....
Top answer 1 of 16
664
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))
2 of 16
178
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.
TutorialsPoint
tutorialspoint.com โบ How-to-add-number-of-days-to-JavaScript-Date
How to add number of days to JavaScript Date?
<!DOCTYPE html> <html> <head> <title>Example- add number of days to the Date object</title> </head> <body> <h2> Add Number of days to the JavaScript Date object using setDate( ) method </h2> <p> Click on the button to add 2 days to the current date/time.</p> <button onclick="add()">Click ...
Tutorial Republic
tutorialrepublic.com โบ faq โบ how-to-format-javascript-date-as-yyyy-mm-dd.php
How to Format JavaScript Date as YYYY-MM-DD
// Create a date object from a ...ng("default", { day: "2-digit" }); // Generate yyyy-mm-dd date string var formattedDate = year + "-" + month + "-" + day; console.log(formattedDate); // Prints: 2022-05-04 ยท Here are some more ...
TutorialsTeacher
tutorialsteacher.com โบ javascript โบ javascript-date
JavaScript Date: Create, Convert, Compare Dates in JavaScript
var date1 = new Date("February 2015-3"); var date2 = new Date("February-2015-3"); var date3 = new Date("February-2015-3"); var date4 = new Date("February,2015-3"); var date5 = new Date("February,2015,3"); var date6 = new Date("February*2015,3"); var date7 = new Date("February$2015$3"); var date8 = new Date("3-2-2015"); // MM-dd-YYYY var date9 = new Date("3/2/2015"); // MM-dd-YYYY
date-fns
date-fns.org
date-fns - modern JavaScript date utility library
date-fns provides the most comprehensive yet simple and consistent toolset for manipulating JavaScript dates in a browser & Node.js.
W3Schools
w3schools.com โบ js โบ js_date_formats.asp
JavaScript Date Formats
The ISO 8601 syntax (YYYY-MM-DD) is also the preferred JavaScript date format: const d = new Date("2015-03-25"); Try it Yourself ยป ยท The computed date will be relative to your time zone. Depending on your time zone, the result above will vary between March 24 and March 25. ISO dates can be written without specifying the day (YYYY-MM):