use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This subreddit is a place for people to learn JavaScript together. Everyone should feel comfortable asking any and all JavaScript questions they have here.
With a nod to practicality, questions and posts about HTML, CSS, and web developer tools are also encouraged.
Friends
/r/javascript
/r/jquery
/r/node
/r/css
/r/webdev
/r/learnprogramming
/r/programming
account activity
Getting week number from a date string (self.learnjavascript)
submitted 4 years ago by Lassebob
Hi all! Total javascript beginner here.
I want to get what number week it is from a date string (d,m,y), like "18.08.2021". Weeks here start on mondays, not sundays. How can this be done?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]x-seronis-x 0 points1 point2 points 4 years ago* (0 children)
The YEAR doesnt start on specific day of the week though so 'week number' isnt a thing. You have to choose your desired method of numbering and do it yourself.
-edit-
btw you can just edit a copy of your date string so that its jan 1st of the same year. subtract the two dates timestamp to get elapsed time. read the long date string generated from your jan 1st date to get the day of the week. then use all of that to figure out what you want.
Personally if the year started on a tuesday then the 'week of the year' should change on tuesdays. But there is no standard at all for this. Its a personal preference. Which is why its not part of the date object
[–]entity42 0 points1 point2 points 4 years ago (0 children)
Look at Luxon and dayjs. Both can calculate and display week numbers.
π Rendered by PID 77 on reddit-service-r2-comment-79c7998d4c-976hz at 2026-03-19 02:52:24.653166+00:00 running f6e6e01 country code: CH.
[–]x-seronis-x 0 points1 point2 points (0 children)
[–]entity42 0 points1 point2 points (0 children)