Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

moment get week


const currentWeekNumber = moment().week()

const weekNumberFromDay = moment('yyyy-mm-dd').week()
Comment

moment get weekday name

var m = moment().day(); // gives 4 for thursday, then you can do a switch
Comment

get week number of month from date moment

function test(mJsDate){
   var str = mJsDate.toLocaleString().substring(0, 3) +
             " number " + Math.ceil(mJsDate.date() / 7) +
             " of the month";
   return str;
}

for(var i = 1; i <= 31; i++) {
   var dayStr = "2014-01-"+ i;
   console.log(dayStr + " " + test(moment(dayStr)) );
}

//examples from the console:
//2014-01-8 Wed number 2 of the month
//2014-01-13 Mon number 2 of the month
//2014-01-20 Mon number 3 of the month
//2014-01-27 Mon number 4 of the month
//2014-01-29 Wed number 5 of the month
Comment

PREVIOUS NEXT
Code Example
Javascript :: can i pass data with usenavigate react router 
Javascript :: how to create a package.json file in npm 
Javascript :: js trigger window resize 
Javascript :: js onload 
Javascript :: puppeteer get attribute 
Javascript :: how to change attribute link in javascript 
Javascript :: js input type range get value while sliding 
Javascript :: next js getserversideprops 
Javascript :: angular show time ago 
Javascript :: momentTimeZone 
Javascript :: difference between .touched & .dirty in angular 
Javascript :: setimmediate vs settimeout 
Javascript :: last element in javascript 
Javascript :: react-native android build apk 
Javascript :: javascript add 1 day to new date 
Javascript :: regex for non empty string 
Javascript :: how to get the integer part of a string in javascript 
Javascript :: angular filter ngfor 
Javascript :: react native import svg image 
Javascript :: sotre json on chrome storage 
Javascript :: javascript xor 
Javascript :: javascript string contains string 
Javascript :: discord.js remove reaction 
Javascript :: number of repetition in an array javascript 
Javascript :: windows how to set process.env variables 
Javascript :: jquery on change 
Javascript :: remove duplicate json object from array javascript 
Javascript :: add event listener in react useeffect 
Javascript :: javascript format float 
Javascript :: remove node modules command windows 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =