Answer the question
In order to leave comments, you need to log in
How to filter items by day?
You need to filter by an array with objects for a week, day, month.
The object stores a specific day.
Data format:
"test": [
{
"id": "uVB6FJQUH",
"type": "kino",
"total": 70,
"date": "17.01.2021",
}]
Answer the question
In order to leave comments, you need to log in
you can use the date-fns library . Namely, the methods:
const lastBusinessWeekStart = subBusinessDays(new Date(), 7);
const lastBusinessMonthStart = subBusinessDays(new Date(), 30);
// фильтр неделя:
test.filter(({ date }) => isWithinInterval(
new Date(date),
{ start: lastBusinessWeekStart, end: new Date() }
));
//фильтр месяц:
test.filter(({ date }) => isWithinInterval(
new Date(date),
{ start: lastBusinessMonthStart, end: new Date() }
));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question