Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

difference between 2 date times node js

const moment = require('moment'); // need to install run - npm run moment
const orderingDate = '2022-09-14T16:19:38.212+00:00';
const format = 'YYYY-MM-DD H:mm:ss';
const currentDate = moment(new Date()).format(format);
const recevingDate = moment(new Date(orderingDate)).format(format);
const differ = new Date(recevingDate) - new Date(currentDate);
let days = parseInt(differ / (1000 * 60 * 60 * 24)); //
let hours = parseInt(differ / (1000 * 60 * 60)); //
let min = parseInt(differ / (1000 * 60)); //
console.log('days', days, 'hours', hours, 'min', min);
 
PREVIOUS NEXT
Tagged: #difference #date #times #node #js
ADD COMMENT
Topic
Name
5+6 =