

The Moment JS is the special library in JavaScript to manage the Date objects. In the above example, we have successfully subtract the 20 minutes in the form of milliseconds from the oldDate object and we get the above output.

Let newDate = new Date(totalMilliSeconds - millisecondsToSubtract) Let totalMilliSeconds = oldDate.getTime() subtracting the 20 minutes from the T09:33:10 Subtracting the 20 minutes from the T05:30:40 : Subtract the Minutes from the date using the getTime() method. The below example demonstrate to subtract the minutes from the date in the form of milliseconds. It is the total minutes which users wants to subtract from the date. Minutes − Users need to replace minutes with the numeric value. Let newDate = new Date ( totalMilliSeconds – millisecondsToSubtract ) Parameters Let millisecondsToSubtract = minutes * 60 * 1000 Users can multiply the minutes by 60 seconds * 1000 milliseconds to convert the minutes tomilliseconds.īelow, users can see the syntax to use this approach. Subtract the Minutes from the Date in the Millisecond Formatįirst we will use the getTime() method to get the total milliseconds of the date.Īfter that, we will subtract the minutes from the total milliseconds in the form of milliseconds. In the second output, users can see that they will get date and time after subtracting the 40 minutes from the current time. subtracting the 40 minutes from the current time Let difference = newdate.getMinutes() - 132 substracting the 132 minutes from the J11:30:25 Let date2 = document.getElementById("date2") Let date1 = document.getElementById("date1") Subtract the 40 minutes from the current time. Subtract 132 minutes from the J11:30:25 : The getMinutes() and setMinutes() methods in JavaScript. The below example demonstrates the above approach. As this parameter you can pass a date and time to initialize date object with it, otherwise it initializes the date object with the current date and time. Set_date − It is an optional parameter for the object of date class. Let difference = date.getMinutes() – minutes_to_substract // find difference between minutes tMinute( difference ) // set new minutes Parameters Syntax let date = new Date(set_date) // create new object of the date class. Users can follow the below syntax to use the getMinutes( ) and setMinutes( ) method. In the next step, we will set the new minutes to the date object using the setMinutes() method of the date class.
#Date now minus minutes update
In this approach, we will create a new date object and extract the minutes from that using the getMinutes() method.Īfter that, we will update the minutes by subtracting the minutes from the minutes we got from the date. Using the getMinutes() and setMinutes() Methods In this tutorial, we will learn to subtract the minutes from the date in vanilla JavaScript using the date object and the Moment JS library.

All JavaScript programmers are lucky enough that JavaScript contains the built-in date class with hundreds of different methods. While developing the applications, programmers need to play with the dates many times. In this tutorial, we will learn to subtract minutes from the date in JavaScript.
