Checking the time difference 24 hours from now using Moment Checking the time difference 24 hours from now using Moment mongoose mongoose

Checking the time difference 24 hours from now using Moment


You can use moment diff method.

Here a working example:

function checkTime(item) {  var currentTime = moment();  var timeStore = moment(item.created);    return currentTime.diff(timeStore, 'h');}// Example Date object representing 5 hours agovar item = {created: moment().subtract(5, 'h').toDate()};var res = checkTime(item);console.log(res); // 5
<script src="//cdnjs.cloudflare.com/ajax/libs/moment.js/2.17.1/moment.min.js"></script>