Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Get Week of Year in Javascript
Date.prototype.getWeek = function() {
var jan4th = new Date(this.getFullYear(),0,4);
return Math.ceil((((this - jan4th) / 86400000) + jan4th.getDay()+1)/7);
}
var now = new Date();
var weekNumber = now.getWeek();
console.log(weekNumber);
@Alevale

This comment has been minimized.

Copy link

Alevale commented May 23, 2018

Seems like it's not correct,

Sunday 3 January 2010 is written as "2009-W53-7" but with this it shows that the weeknumber is "1"
Monday 29 December 2008 is written "2009-W01-1" same here, the week should be 01 and it shows 53

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.