Created
July 27, 2013 18:59
-
-
Save HomerJSimpson/6095906 to your computer and use it in GitHub Desktop.
calculate last friday in month in javascript
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
/*jslint white:true */ | |
/*global console */ | |
function lastFridayOfMonth(year, month) { "use strict"; | |
var lastDay = new Date(year, month+1, 0); | |
if(lastDay.getDay() < 5) { | |
lastDay.setDate(lastDay.getDate() - 7); | |
} | |
lastDay.setDate(lastDay.getDate() - (lastDay.getDay() -5)); | |
return lastDay; | |
} | |
var year, month; | |
for(year=2017;year >= 2013;year -= 1) { | |
for(month=11;month >= 0;month -= 1) { | |
var day = lastFridayOfMonth(year, month), dm7 = new Date(+day); | |
console.log(day.getDay() + " " + day + " " + dm7); | |
} | |
console.log(); | |
console.log(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
superb......!