How do I get the current weeknumber of the year, like PHP’s date('W')?
It should be the ISO-8601 week number of year, weeks starting on Monday.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should be able to get what you want here:
http://www.merlyn.demon.co.uk/js-date6.htm#YWD.A better link on the same site is:
Working with weeks.Edit
Here is some code based on the links provided and that posted eariler by Dommer. It has been lightly tested against results at
http://www.merlyn.demon.co.uk/js-date6.htm#YWD. Please test thoroughly, no guarantee provided.Edit 2017
There was an issue with dates during the period that daylight saving was observed and years where 1 Jan was Friday. Fixed by using all UTC methods. The following returns identical results to Moment.js.
Hours are zeroed when creating the "UTC" date.
Minimized, prototype version (returns only week-number):
Test section
In this section, you can enter any date in YYYY-MM-DD format and check that this code gives the same week number as Moment.js ISO week number (tested over 50 years from 2000 to 2050).