How to compare two dates with moment js. I used diff() method , but not worked. How I solve it ?
let lastMessageMinute = moment("06-30-2022").format("HH:mm");
let currentTime = moment(new Date()).format("HH:mm");
const differenceOfTimes = currentTime.diff(lastMessageMinute, "hours");
Convert both dates (before formatting) to milliseconds and compare them. Like
if(lastMessageMinute.valueOf() === currentTime.valueOf())
you need to do like moment().diff()
Your syntax -> moment().format().diff() this is not accept by moment js.
For Example,
var a = moment("18.05.2022", "DD.MM.YYYY");
var b = moment(new Date(), "DD.MM.YYYY");
console.log("diff", b.diff(a, 'hours'));