Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

78
Views
Moment js. Comparison two dates

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");
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Convert both dates (before formatting) to milliseconds and compare them. Like

if(lastMessageMinute.valueOf() === currentTime.valueOf())
about 4 years ago · Juan Pablo Isaza Report

0

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'));
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!