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

134
Views
How to check if value is 10 or more minutes from now?

I'd like to check if value is 10 or more mins from now.

let now = new Date().getTime();
let TEN_MINUTES = new Date().getTime() + 600000;

let val = '2022-01-14 12:27:05+00:00'


if(val > TEN_MINUTES){
   console.log('true')
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

val is a non-blank string, so val > tenMinsPlus doesn't make any sense, since tenMinsPlus is a boolean.

If you want to know whether val is more than ten minutes from now, you need to get a date-like value for val and a date-like value for ten minutes from now, and compare them.

You're getting TEN_MINUTES correctly:

let TEN_MINUTES = new Date().getTime() + 600000;

although you can do that more concisely:

let TEN_MINUTES = Date.now() + 600000;

Both of those give us a number of milliseconds since The Epoch (Jan 1st 1970 at midnight UTC) for "now" plus ten minutes.

Now let's do the date. Your string is almost in a valid format for the Date object to parse. It just needs the space after the date changed into a T, then we can use Date.parse to parse it and give us the number of milliseconds since The Epoch:

let then = Date.parse(val.replace(" ", "T"));

Then we see whether then is greater than TEN_MINUTES:

if (then > TEN_MINUTES) {
    // Yes, it's more than ten minutes from now
} else {
    // No, it isn't
}

Live Example:

function moreThan10Minutes(val) {
    let TEN_MINUTES = Date.now() + 600000;
    let then = Date.parse(val.replace(" ", "T"));
    return then > TEN_MINUTES;
}
function test(val) {
    const result = moreThan10Minutes(val);
    if (result) {
        console.log(`Yes, ${val} is more than 10 minutes from now`);
    } else {
        console.log(`No, ${val} is not more than 10 minutes from now`);
    }
}

test("2022-01-14 12:27:05+00:00");
test(new Date(Date.now() + 700000).toISOString());

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!