How to subtract minutes from a date in JavaScript?

Sometimes, we want to subtract minutes from a date in JavaScript.

In this article, we’ll look at how to subtract minutes from a date in JavaScript.

How to subtract minutes from a date in JavaScript?

To subtract minutes from a date in JavaScript, we can subtract the timestamp in milliseconds from the current date.

For instance, we write

const MS_PER_MINUTE = 60000;
const myStartDate = new Date(myEndDateTime - durationInMinutes * MS_PER_MINUTE);

to subtract the myEndDateTime timestamp in milliseconds by the durationInMinutes * MS_PER_MINUTE milliseconds, which is the durationInMinutes converted to milliseconds.

Then we pass that into the Date constructor to create a new date object.

Conclusion

To subtract minutes from a date in JavaScript, we can subtract the timestamp in milliseconds from the current date.