How To Date Sub Month Using Node Js?

Dec 22, 2021 . Admin



Hello Friends,

Now let's see example of how to date sub month example. We will check how to date sub month. This is a short guide on date sub month in node js. Let's get started with how to date sub month in node js.

Here i will give you many example how to date sub month using node js.

Example 1 :

Step 1 : Create Node App

Run following command to create node app.

mkdir my-app
cd my-app
 
npm init
Step 2 : Create server.js file

server.js

let subMonth = new Date();
let finalDate = new Date(subMonth.setMonth(subMonth.getMonth() - 1));

console.log(subMonth);

now you can simply run by following command:

node server.js
Output :
2021-11-15T12:10:29.861Z

Example 2 :

Step 1 : Create Node App

Run following command to create node app.

mkdir my-app
cd my-app
 
npm init
Step 2 : Create server.js file

server.js

var subMonth = new Date("April 27, 2021 11:10:50");
subMonth.setMonth( subMonth.getMonth() - 1 );

var monthTime = subMonth.toLocaleString();
console.log(monthTime);

now you can simply run by following command:

node server.js
Output :
27/3/2021, 11:10:50 am

It will help you...

#Node JS