Skip to content

Instantly share code, notes, and snippets.

@HomerJSimpson
Created July 27, 2013 18:59
Show Gist options
  • Save HomerJSimpson/6095906 to your computer and use it in GitHub Desktop.
Save HomerJSimpson/6095906 to your computer and use it in GitHub Desktop.
calculate last friday in month in javascript
/*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();
}
@Dharmadurai95
Copy link

superb......!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment