Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Moment.js to find a specific day of the current week's date

People also ask

How do you find the day of the week in the moment?

Syntax. moment(). weekday(Number); moment(). weekday();

How do I get the current day of the week in JavaScript?

Call the getDay() method on the Date object to get the day of the week. The getDay method returns the day of the week for the specific date, represented as an integer between 0 and 6 , where 0 is Sunday and 6 is Saturday.

How do you find the day of the month in a moment?

The moment(). daysInMonth() function is used to get the number of days in month of a particular month in Node.


this week's sunday

moment().startOf('week')

this week's monday

moment().startOf('isoweek')

this week's saturday

moment().endOf('week')

difference between the current day to sunday

moment().diff(moment().startOf('week'),'days')

this week's wedesday

moment().startOf('week').add('days', 3)

Maybe a little late to the party, but here's the proper way to do this, as in the documentation.

moment().day(1); // Monday in the current week

Also if in your locale it happens that the week starts with Monday and you wish to get a locally aware result, you can use moment().weekday(0). Here's the documentation for the moment().weekday(dayNumber) method.


It's not longer possible to use just a string (e. g. 'isoweek'), we need to use it like this:

import * as moment from 'moment';
import { unitOfTime } from 'moment';

moment().startOf('isoweek' as unitOfTime.StartOf);