Skip to content

Instantly share code, notes, and snippets.

@keelii
Last active August 29, 2015 14:12
Show Gist options
  • Save keelii/55b2cb3c4d87de846a8e to your computer and use it in GitHub Desktop.
Save keelii/55b2cb3c4d87de846a8e to your computer and use it in GitHub Desktop.
how many weeks from now to sometime
function nWeekFromNow(ts) {
var now = new Date();
now.setHours(0);
now.setMinutes(0);
now.setSeconds(0);
now.setMilliseconds(0);
var nowTS = now.getTime();
var nowDay = now.getDay() || 7;
var startTS = nowTS - (nowDay - 1) * 24 * 60 * 60 * 1000;
var nWeek = Math.ceil( Math.abs(startTS - ts) / 1000 / 60 / 60 / 24 / 7 );
return ts >= startTS ? 0 : nWeek;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment