Skip to content

Instantly share code, notes, and snippets.

@TurRil
Forked from IamSilviu/Get week number
Created August 27, 2017 11:21
Show Gist options
  • Select an option

  • Save TurRil/47d44c0e80e1fe882ca87672ddcb1614 to your computer and use it in GitHub Desktop.

Select an option

Save TurRil/47d44c0e80e1fe882ca87672ddcb1614 to your computer and use it in GitHub Desktop.
JavaScript Get week number.
Date.prototype.getWeek = function () {
var onejan = new Date(this.getFullYear(), 0, 1);
return Math.ceil((((this - onejan) / 86400000) + onejan.getDay() + 1) / 7);
};
var myDate = new Date("2001-02-02");
myDate.getWeek(); //=> 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment