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

254
Views
dayjs - Calculate difference between hours and return it in minutes

Given two time parameters like: "13:00" and "00:00" How can I calculate the difference backwards and return it in minutes? My expected result is 780. Parameters can be 13:30. 13:45 etc.

API doc did not help, https://day.js.org/docs/en/display/difference, everybody is calculating date difference, not hours.

Thanks!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You don't need a library to do this.

You can split the strings by a colon, then use the Date constructor to parse the hour and minutes. You can then subtract the two Dates to get the millisecond difference, and divide by 60000 to get the number of minutes:

const a = "00:00";
const b = "13:00"



function calcDiff(start, end) {
  const [startHour, startMinutes] = start.split(":")
  const [endHour, endMinutes] = end.split(":")

  const diff = (new Date(null, null, null, endHour, endMinutes) - new Date(null, null, null, startHour, startMinutes)) / 60000
  return diff;
}

console.log(calcDiff(a, b))

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!