Moment js get specific day of a month by week and day of week

Viewed 4530

How to get second Tuesday of a given month or get third Thursday of a given month using moment js.

I tried finding a solution but was unsuccessful. I wrote it myself and posted the answer below and if you have a better solution u can answer your implementation.

4 Answers

Get the date of the 2nd Tuesday of this month:

var date = new Date();
var month_week = 2; // 2nd Week
var week_day = 2; // Tuesday

var first_week = moment(date).startOf("month").day(week_day);
var result = first_week.add(7 * (month_week - 1), "days");

console.log(result);
<script src="https://momentjs.com/downloads/moment.min.js"></script>

Related