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 :: js array delete specific element 
Javascript :: Sort Date string in javascript 
Javascript :: dynamic key in javascript object 
Javascript :: get body 
Javascript :: replace element javascript 
Javascript :: React passing data fom child to parent component 
Javascript :: array of objects in javascript 
Javascript :: js for loop 
Javascript :: react in jquery 
Javascript :: some js 
Javascript :: react datetime mannual editing 
Javascript :: js string encode decode arabic 
Javascript :: identifier in js 
Javascript :: javascript change get parameter without reload 
Javascript :: import css files maven resources with jsf 
Javascript :: react native onrefresh stuck release 
Javascript :: include antoher file wagger 
Javascript :: bootstrap 4 without javascript 
Javascript :: angular append to FormControl errors 
Javascript :: how to push into an array javascript 
Javascript :: naming a function in javascript 
Javascript :: how to install node js in plesk 
Javascript :: $(document).ready(function() { $(".more-items").click(function() { $(this).parent().find(".more").slideToggle(); }); }); 
Javascript :: Getting Nan when calculate two date js 
Javascript :: find max of countby 
Javascript :: react native bordered image drop with shadow fix 
Javascript :: what is steal.js 
Javascript :: jstree select all visible node only 
Javascript :: javascript loop payment 
Javascript :: train function ajax 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =