How To Date Add Days Using Node Js?
Dec 16, 2021 . Admin
Hello Friends,
Now let's see example of how to date add days example. We will check how to date add days. This is a short guide on date add days in node js. Let's get started with how to date add days in node js.
Here i will give you many example how to date add days using node js.
Example 1 :
Run following command to create node app.
mkdir my-app cd my-app npm initStep 2 : Create server.js file
server.js
var dtAdd = 2; var addDays = new Date(Date.now() + dtAdd * 24*60*60*1000); console.log('Today: '); console.log(new Date()); console.log('New: '); console.log(addDays);
now you can simply run by following command:
node server.jsOutput :
Today: 2021-12-14T11:20:26.293Z New: 2021-12-16T11:20:26.290Z
Example 2 :
Step 1 : Create Node AppRun following command to create node app.
mkdir my-app cd my-app npm initStep 2 : Create server.js file
server.js
Date.prototype.addDays = function(days) { this.setDate(this.getDate() + parseInt(days)); return this; }; var newDt = new Date().addDays(4); console.log(newDt);
now you can simply run by following command:
node server.jsOutput :
2021-12-18T11:28:40.898Z
It will help you...