I need some help, because I'm struggling for some time with this issue, I'm trying to filter the days from this week, excluding today and yesterday, because I have separate stacks for them. I want to filter only days that are older than yesterday, but between this week. Other filter is that I want days older than this week (from last 2 weeks).
So here is my code:
const filterByDate = (data) => {
const tempStacks = {} as any;
const date = new Date();
const yesterday = new Date(new Date().setDate(date.getDate() - 1));
console.log('yesterday', yesterday.getDate())
const getWeek = (d) => {
const dt: any = new Date(d.getFullYear(),0,1);
return Math.ceil((((d - dt) / 86400000) + dt.getDay())/7);
};
const thisWeek = getWeek(date);
console.log('this week', thisWeek)
console.log('test date----', new Date(new Date().setDate(new Date().getDate() - 7)))
tempStacks.today = data.filter(obj => {
return obj.date.getDate() === date.getDate()
&& obj.date.getMonth() === date.getMonth()
&& obj.date.getFullYear() === date.getFullYear()
});
tempStacks.yesterday = data.filter(obj => {
return obj.date.getDate() === yesterday.getDate()
&& obj.date.getMonth() === yesterday.getMonth()
&& obj.date.getFullYear() === yesterday.getFullYear()
});
console.log('tempStacks yesterday', tempStacks.yesterday)
tempStacks.thisWeek = data.filter(obj => {
return getWeek(obj.date) === thisWeek
})
tempStacks.lastTwoWeeks = data.filter(obj => {
return getWeek(obj.date) === thisWeek-1 || getWeek(obj.date) === thisWeek-2
})
return tempStacks;
}
The problem that I have with my code is that in thisWeek
stack, I have all days from this week, including yesterday
and today
and I want them to be excluded, since I have separate stacks for them.
Anyone knows a fine solution for this issue that I have?