Skip to content

Instantly share code, notes, and snippets.

@JustinMorgan
Last active October 20, 2015 21:50
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 JustinMorgan/46a5bd81eb750c6fa7ab to your computer and use it in GitHub Desktop.
Save JustinMorgan/46a5bd81eb750c6fa7ab to your computer and use it in GitHub Desktop.
Which number week of the year is it?
function weekNumber(date) {
var currYear = date.getFullYear();
var jan1 = new Date(currYear,0,1);
return Math.ceil((((date - jan1) / 86400000) + jan1.getDay() + 1)/7);
}
function weekNumberUTC(date) {
var currYear = date.getUTCFullYear();
var jan1 = new Date(currYear,0,1);
return Math.ceil((((date - jan1) / 86400000) + jan1.getUTCDay() + 1)/7);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment