Check this out:
Using vanilla JS date object, you can find the difference in minutes between two dates.
Example:
const today = new Date(); // This represents the current date + time
const difference = parseInt(
(Math.abs(today.getTime() - OTHERDATEOBJECT.getTime()) / (1000 * 60)) % 60);
// Handling the difference
if (difference > 5) {
// Do something if it was at least 5 minutes ago
} else {
// If not 5 minutes ago, do something else
}
If you are passing it a date string, you may need to create a new date object with it before you can compare it to your "today" date object
like so:
const difference = parseInt(
(Math.abs(today.getTime() - (new Date(OTHERDATE)).getTime()) / (1000 * 60)) % 60);