Skip to content

Instantly share code, notes, and snippets.

@black-black-cat
Forked from IamSilviu/Get week number
Last active January 30, 2019 08:13
Show Gist options
  • Save black-black-cat/526d8eb772f8f152656a791357d757c7 to your computer and use it in GitHub Desktop.
Save black-black-cat/526d8eb772f8f152656a791357d757c7 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);
var today = new Date(this.getFullYear(), this.getMonth(), this.getDate());
return Math.ceil((((today - 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