Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
96
rated 0 times [  100] [ 4]  / answers: 1 / hits: 143291  / 10 Years ago, sat, september 20, 2014, 12:00:00

How could I get from moment JS the week number from a date in the past only from a moment formatted object from a day selected?


More From » momentjs

 Answers
2
  $(document).ready(function(){
var weeknumber = moment(12-25-1995, MM-DD-YYYY).week();
console.log(weeknumber);
});


According momentjs docs:




Because different locales define week of year numbering differently,
Moment.js added moment#week to get/set the localized week of the year.



The week of the year varies depending on which day is the first day of
the week (Sunday, Monday, etc), and which week is the first week of
the year.



For example, in the United States, Sunday is the first day of the
week. The week with January 1st in it is the first week of the year.




So, if you are having problems getting the right week number use .isoWeek()



$(document).ready(function(){
var weeknumber = moment(11-26-2016, MMDDYYYY).isoWeek();
alert(weeknumber);
});


Example


[#69386] Thursday, September 18, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
turnerf

Total Points: 620
Total Questions: 101
Total Answers: 109

Location: French Polynesia
Member since Tue, Jul 7, 2020
4 Years ago
turnerf questions
;