The 3rd Tuesday of this month is on day
function nth_zday(nth, zday, fdate) {
// nth: 1=1st, 2=2nd, 3=3rd, 4=4th, 5=5th
// zday: 0=Sun, 1=Tue, ..., 6=Sat
// fdate: null (curr date) or date of interest
fdate = fdate || new Date();
// get day of week for first day of given month
// calculate first zday
// add in the number of weeks forward
fdate.setDate(1);
var fom = fdate.getDay();
var monthDay = ((7 + zday - fom)%7) + ((nth-1)*7) + 1;
// check for day > end of month
// this utilizes Date()'s processing of days past the end of the month
// Date(2018,08,36) => 2018/09/05
var valiDate = new Date(fdate.getFullYear(), fdate.getMonth(), monthDay);
if (fdate.getMonth() == valiDate.getMonth()) {
return monthDay
} else {
return false;
}
}