Skip to content

Instantly share code, notes, and snippets.

@lehtu
Last active November 9, 2016 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lehtu/773929ccf844034f775cc5a04fb3d0dd to your computer and use it in GitHub Desktop.
Save lehtu/773929ccf844034f775cc5a04fb3d0dd to your computer and use it in GitHub Desktop.
Calculates all dates between input dates and gives dates every week for the week day by start date.
// working demo in here: https://jsfiddle.net/lehtu/awnuk9f1/
var moment = require('moment');
var start = '2016-01-01';
var end = '2016-12-31';
var weeks = moment(end).diff(start, 'week');
var dates = [];
for (var i = 0; i <= weeks; i++) {
dates.push(moment(start).add(i, 'weeks'));
}
// just for seeing that dates are correct
dates.forEach(function(date) {
console.log(date.format('YYYY-MM-DD : dddd'));
});
console.log("there is " + i + " week(s) between given dates");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment