0

How to get week number in US format. I tried this code but it is not correct.

   Date.prototype.getWeekNumber = function (date) {
                        var d = new Date(date);
                        d.setHours(0, 0, 0);
                        d.setDate(d.getDate() + 4 - (d.getDay() || 7));
                        return Math.ceil((((d - new Date(d.getFullYear(), 0, 1)) / 8.64e7) + 1) / 7);
                    };
3
  • 1
    What exactly is different in the US week number compared to the 'common' week number? This question seems similar: stackoverflow.com/questions/7765767/… Commented Jul 22, 2014 at 11:36
  • Agree with @MeanGreen Commented Jul 22, 2014 at 11:43
  • 1
    onlineconversion.com/day_week_number.htm try this site and enter pls enter 09/12/2014. It will give 36 as US standrad week number and 37 as ISO Commented Jul 22, 2014 at 11:46

1 Answer 1

0

It's a little trickier than that. The first week of the year starts with the first Thursday of the year. So really, you probably should count how many Thursdays have passed in that year for the given date.

Taken from Wikipedia: https://en.wikipedia.org/wiki/Week_number#Week_numbering

For example, week 1 of 2004 (2004W01) ran from Monday 29 December 2003 to Sunday, 4 January 2004, because its Thursday was 1 January 2004, whereas week 1 of 2005 (2005W01) ran from Monday 3 January 2005 to Sunday 9 January 2005, because its Thursday was 6 January 2005 and so the first Thursday of 2005. The highest week number in a year is either 52 or 53 (it was 53 in the year 2004).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.