Created
January 14, 2015 21:45
-
-
Save dillten/d0bb1a90bbddab95499d to your computer and use it in GitHub Desktop.
Get the second Monday of the month using moment.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mo = require('moment'); | |
function getSecondMonday(startDate) { | |
var startOfMonth = mo(startDate).utc().startOf('month').startOf('isoweek'); | |
var studyDate = mo(startDate).utc().startOf('month').startOf('isoweek').add(2, 'w'); | |
if (studyDate.month() == startOfMonth.month()) { | |
studyDate = studyDate.subtract(1, 'w'); | |
} | |
return studyDate; | |
} | |
for(var i = 0; i < 20; i++) { | |
var startOfMonth = mo().utc().subtract(i, 'M'); | |
console.log(getSecondMonday(startOfMonth).toISOString()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@ashwin-chandrappa check this link
https://github.dev/a-vi-nash/js-helpers/blob/main/getNthWeekday.js