Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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);
Source by momentjscom.readthedocs.io #
 
PREVIOUS NEXT
Tagged: #moment #previous #week #dates #today
ADD COMMENT
Topic
Name
6+6 =