Filter Array in Array by date between 2 dates
let start = new Date(this.min);
let end = new Date(this.max);
return items.filter(item => {
let date = new Date(item.created_at);
return date >= start && date <= end;
}
I had an issue with this when the end date was the same as the start date to solve this issue I had to set the time on the end date to 23.59
const start = new Date().getTime()
const end=new Date()
end.setHours(23,59,59,999)
end.getTime()
return items.filter(item => {
let date = new Date(item.created_at).getTime();
return date >= start && date <= end;
}
You need to return
the compairing value, either explicit
data.series = data.series.filter((item: any) => {
return item.date.getTime() >= fromDate.getTime() &&
item.date.getTime() <= toDate.getTime();
});
or without the brackets, implicit.
data.series = data.series.filter((item: any) =>
item.date.getTime() >= fromDate.getTime() && item.date.getTime() <= toDate.getTime()
);