Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

moment get week


const currentWeekNumber = moment().week()

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

moment get previous one week dates from today

const fromDate = moment();
const toDate = moment().subtract(6, 'days');

const enumerateDaysBetweenDates = (startDate, endDate) => {
    let foundDates = [];

    while (endDate.isSameOrBefore(startDate)) {
        foundDates.push(`${endDate.format("YYYY-MM-DD")}`);
        endDate.add(1, "days");
    }
    return foundDates;
};

const results = enumerateDaysBetweenDates(fromDate, toDate);
console.log("results: ", results);
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 :: use import in node 
Javascript :: angular input value 
Javascript :: apk react native 
Javascript :: livewire progress indicators javascript 
Javascript :: json rename key 
Javascript :: react make component full screen 
Javascript :: how to get time and date from iso string javascript 
Javascript :: javascript check if json file is empty 
Javascript :: js select element by css selector 
Javascript :: javascript for loop on object 
Javascript :: jquery visible 
Javascript :: replace array element javascript 
Javascript :: draw line in javascript 
Javascript :: jquery validate checkbox before submit 
Javascript :: button size react native 
Javascript :: javascript set width percentage update 
Javascript :: reverse date javascript from yyyy/mm/dd to dd/mm/yyyy 
Javascript :: vue shortcut to create component 
Javascript :: sort javascript array 
Javascript :: Import file to mongodb database 
Javascript :: form validation using jquery 
Javascript :: eas build apk 
Javascript :: jquery value of input 
Javascript :: refresh after delete in node 
Javascript :: binary agents freecodecamp 
Javascript :: unique string id js 
Javascript :: javascript get all classes 
Javascript :: date-and-time npm 
Javascript :: write to console using jQuery 
Javascript :: nuxt input mask 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =