Moment.js moment().date() Method Last Updated : 18 Jul, 2022 Comments Improve Suggest changes Like Article Like Report The moment().date() method is used to get or set the day of the month of the Moment object. The range for setting the day can be between 1 and 31. When the range is exceeded, the day will extend to the previous or next months. This is also the same case in months that do not have all the 31 days, and hence will go to the next month when using a larger value. Syntax: moment().date( Number ); Parameters: This method accepts a single parameter as mentioned above and described below: Number: It is the day of the month that has to be set for the Moment object. it is an optional parameter. Return Value: This method returns the day of the month of the Moment. Note: This will not work in the normal Node.js program because it requires an external moment.js library to be installed globally or in the project directory. 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().date() Method. Example 1: JavaScript const moment = require('moment'); console.log("Current Date:", moment().toString()) console.log("Current date is:", moment().date()) let date10 = moment().date(10); console.log( "Moment with date of 10 is:", date10.toString() ) let date30 = moment().date(30); console.log( "Moment with date of 30 is:", date30.toString( )) Output: Current Date: Mon Jul 18 2022 01:49:32 GMT+0530Current date is: 18Moment with date of 10 is: Sun Jul 10 2022 01:49:32 GMT+0530Moment with date of 30 is: Sat Jul 30 2022 01:49:32 GMT+0530 Example 2: JavaScript const moment = require('moment'); let momentX = moment().year(2019).month(6).date(5); console.log("momentX Date:", momentX.toString()) console.log("momentX date is:", momentX.date()) let date45 = momentX.date(45); console.log( "momentX with date of 45 is:", date45.toString() ) let negativeDate45 = momentX.date(-45); console.log( "momentX with date of -45 is:", negativeDate45.toString() ) Output: momentX Date: Fri Jul 05 2019 01:49:32 GMT+0530momentX date is: 5momentX with date of 45 is: Wed Aug 14 2019 01:49:32 GMT+0530momentX with date of -45 is: Sun Jun 16 2019 01:49:32 GMT+0530 Reference: https://momentjs.com/docs/#/get-set/date/ Comment More infoAdvertise with us Next Article Moment.js moment().add() Method S sayantanm19 Follow Improve Article Tags : Web Technologies Node.js Moment.js Moment.js-Get-Set Similar Reads Moment.js moment().get() Method The moment().get() method is used to get the given unit of time from the Moment object as a String. The unit can be specified in all the recognized variations of the unit including its plural and short forms. It can be used to return the value of a year, month, date, hour, minute, and millisecond. S 2 min read Moment.js moment().add() Method The moment().add() method is used to add the given unit of time to the Moment object. The unit can be specified in all the recognized variations of the unit including its plural and short forms. Syntax: moment().add(Number, String) OR moment().add(Duration) OR moment().add(Object) Parameters: This m 2 min read Moment.js moment().dayOfYear() Method The moment().dayOfYear() method is used to get or set the day of the year of the Moment object. This can be a value between 1 and 366 denoting the first and last possible day of the year. A value outside of this range will set the day for the previous or next years. Syntax: moment().dayOfYear( Numbe 2 min read Moment.js moment().endOf() Method The moment().endOf() method is used to mutate the Moment so that it is set to the end of the given unit of time. The available units of time can be the year, month, quarter, week, day, hour, minute and second. Syntax: moment().endOf( String ); Parameters: This method accepts a single parameter as me 2 min read Moment.js moment.hour() Method The moment.hour() method in Moment.js is used to get or set the hour of a given moment object. It allows you to manipulate or retrieve the hour of a date.Syntax:moment().hour();ormoment().hours();Parameters: This method accepts a single parameter number that you want to set hours then you will requi 2 min read Moment.js moment().inspect() Method The moment().inspect() method is used for debugging of Moment objects by producing a machine-readable string. This string can be used to generate the same Moment object as the current one. It can be also used in Node interactive shells for displaying the Moment object. Note: In some cases may not wo 2 min read Like