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

115
Views
Subtracting time from current time

I have 2 strings, that have the minute and hour that a function needs to occur at.

I want to check, if the minute and hour which are specified in string format, and from my database are within 5 minutes of the current time, call this function.

My original thought was something like:

(today.minute is the current minute)

today.minute:

minute = "55"
hour = "14"
var today = new Date();
var time = today.getMinutes(), today.getHours()

if (today.getMinutes() - 5 == minute) {
   myFunc()
}

But that isn't going to work, because I need the hour and minute - 5 minutes... how can I do this?

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

0

Is this what you are looking for?

let minute = "55"
let hour = "14"
let today = new Date();
//var time = today.getMinutes(), today.getHours()

if (Math.abs(today.getMinutes() - Number(minute)) <= 5) {
   myFunc()
}

function myFunc() {
  console.log('myFunc called', today.getMinutes());
 }

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!