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

moment get start of week in datetime

const today = moment();
const from_date = today.startOf('week');
const to_date = today.endOf('week');
console.log({
  from_date: from_date.toString(),
  today: moment().toString(),
  to_date: to_date.toString(),
});

// {
//   from_date: "Sun Apr 22 2018 00:00:00 GMT-0500",
//   today: "Thu Apr 26 2018 15:18:43 GMT-0500",
//   to_date: "Sat Apr 28 2018 23:59:59 GMT-0500"
// }
Comment

moment js get last week start and end date

console.log(moment().subtract(1, 'weeks').startOf('isoWeek').format('dddd'));
console.log(moment().subtract(1, 'weeks').endOf('isoWeek').format('dddd'));

console.log(moment().subtract(1, 'weeks').startOf('week').format('dddd'));
console.log(moment().subtract(1, 'weeks').endOf('week').format('dddd'));

console.log(moment().subtract(1, 'weeks').startOf('week').format('YYYY-MM-DD'));
console.log(moment().subtract(1, 'weeks').endOf('week').format('YYYY-MM-DD'));
Comment

momentjs get calendar week

  $(document).ready(function(){
    var weeknumber = moment("12-25-1995", "MM-DD-YYYY").week();
    console.log(weeknumber);
  });
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 :: convert fetch data to json 
Javascript :: javascript caps lock 
Javascript :: router navigatebyurl 
Javascript :: make select option selected javascript 
Javascript :: loopback model count 
Javascript :: We often use anonymous functions as arguments of other functions. For example: 
Javascript :: shadow in react native 
Javascript :: how to reload a module in node.js 
Javascript :: javascript reload page 
Javascript :: remove last char - jquery 
Javascript :: jquery on type event 
Javascript :: adding media queries in makeStyle material react 
Javascript :: mongoose unique field 
Javascript :: in puppeteer wait for page untile certain selector have certain value 
Javascript :: jwt token expire times 
Javascript :: Append element to a different parent 
Javascript :: cheerio load from file 
Javascript :: how to make div visible and invisible in javascript 
Javascript :: mongodb add admin user 
Javascript :: encrypt data using SHA256 algorithm in JavaScript 
Javascript :: react query dev tools 
Javascript :: node get root directory 
Javascript :: node es6 import 
Javascript :: store data in array jquery 
Javascript :: js get input from user 
Javascript :: destructuring dynamic properties 
Javascript :: usestate array delete 
Javascript :: finding by sub property of an object in mongo 
Javascript :: jquery set width 
Javascript :: javascript count instances in string 
ADD CONTENT
Topic
Content
Source link
Name
9+5 =