How to subtract minutes from minutes in javascript? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

How to subtract minutes from minutes in javascript?

For example, I need to subtract 20 minus 30 minutes, but when subtracting it turns out minus 10, please help

22nd Jul 2021, 1:12 AM
#-_Scripter_-#
#-_Scripter_-# - avatar
5 Answers
+ 4
Get the value from `Date` object in milliseconds into a variable e.g. <ms> by using valueOf() method. Then you subtract <ms> by number of milliseconds in 30 minutes. Note that there are 60000 milliseconds in a minute, so you multiply that by 30 (minutes). Finally, create a new `Date` object from <ms>. I think it will work, give it a try 👍
22nd Jul 2021, 5:44 AM
Ipang
+ 9
Can you show your code? That helps people figure out what went wrong.
22nd Jul 2021, 1:22 AM
Hatsy Rei
Hatsy Rei - avatar
23rd Jul 2021, 12:22 AM
Calviղ
Calviղ - avatar
+ 5
22nd Jul 2021, 4:15 PM
Calviղ
Calviղ - avatar
+ 2
If there is a solution through jquery, then also write
22nd Jul 2021, 1:13 AM
#-_Scripter_-#
#-_Scripter_-# - avatar