Currently trying to filter my data array by week, I have been able to filter by day quite easily however am struggling with dates between x and y (eg by week).
I have tried setting a start date and end date (today) and then trying to return the dates less than or equal to the start and end dates but am failing.
Data array date format: dd/mm/yyyy (01/01/2000)
The user will select which filter to use (hence switch() ) case 7 being filter by 7 days.
computed: {
appointments: function () {
var today = new Date();
var dd = String(today.getDate()).padStart(2, '0');
var mm = String(today.getMonth() + 1).padStart(2, '0'); //January is 0!
var yyyy = today.getFullYear();
var data = this.$store.state.appointments;
this.filter1_color = "grey";
this.filter2_color = "grey";
switch (this.dateFilter) {
case 0:
break;
case 1:
console.log("case1: " + today)
return data.filter(word => word.date == today);
case 7:
/// WORKING /// (ex. edit)
var week = [];
var today = moment();
var sevenDaysBefore = today.subtract(7, 'days');
for (var i = 0; i < data.length; i++) {
let momentDate = moment(data[i].date, 'DD/MM/YYYY')
let newDate = momentDate.format("DD/MM/YYYY")
if (momentDate.isBetween(sevenDaysBefore, moment(), null, '[]')) week.push(data[i]);
}
return week
///
}
return data;
},
I need to filter the data to only show items in the array with dates equal to the dates in the last 7 days.