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')
}
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());