This page looks best with JavaScript enabled

How to add or subtract minutes from a JavaScript Date object

 ·  ☕ 1 min read  ·  👽 john hashim

This post will show you how to add or subtract minutes based on your projects that involve date objects.

get the present time

to get the present time we create a variable and return it.

1
2
3
let present = new Date();
alert (present)
//present date and time

adding minute to the present time

to add minutes we will use the variable and set minutes we want.

1
2
3
4
let future = new Date();
future.setMinutes(future.getMinutes() + 30)
alert (future)
//future date and time

subtract minutes from present time

this is similar to the above example except that instead of using plus sign you will use the minus

1
2
3
4
let past = new Date();
past.setMinutes(past.getMinutes() - 40)
alert (past)
//past date and time

Thanks for checking out this … leave a comment below on how to add hours, days, weeks , months and years if possible 😀

Share on

john hashim
WRITTEN BY
john hashim
Web Developer