![]() |
VOOZH | about |
The moment().min() method limits the moment to a minimum of another moment value. We can also say that m1.min(m2) is the same as m1 = moment.max(m1, m2). This method is the counterpart of moment.max() method.
Syntax:
moment().min(Moment|String|Number|Date|Array);
Parameters: This method can accept the following parameters as mentioned above and described below:
Return Value: This method returns the Moment object calculated after a comparison of the given parameters.
Note:
Moment.js can be installed using the following command:
Installation of moment module:
npm install moment
The below examples will demonstrate the Moment.js moment().min() Method.
Example 1: In this example, we are comparing the current moment with the moment 15 days before the current date.
Output:
The two Moments are: Mon Aug 29 2022 13:05:38 GMT+0530 Sun Aug 14 2022 13:05:38 GMT+0530 The calculated Moments from the above is: Mon Aug 29 2022 13:05:38 GMT+0530
Example 2: In this example, we are comparing dates, this method will return the maximum of both the dates.
Output:
The two Moments are: Mon Jan 01 2001 00:00:00 GMT+0530 Sat Feb 02 2002 00:00:00 GMT+0530 The calculated Moments from the above is: Sat Feb 02 2002 00:00:00 GMT+0530
Example 3: In this example, we are comparing the array of moments,.
Output:
The three Moments are: Mon Aug 29 2022 13:15:34 GMT+0530 Sun Aug 14 2022 13:15:34 GMT+0530 Tue Sep 13 2022 13:15:34 GMT+0530 The calculated Moment from the above is: Mon Aug 29 2022 13:15:34 GMT+0530