This is my database structure:
[
{
"schedule_time": "2021-05-17 12:39:29",
"slot": "L",
"item_date": "2021-05-18"
},
{
"schedule_time": "2021-05-17 12:47:53",
"slot": "D",
"item_date": "2021-05-18"
},
{
"schedule_time": "2021-05-18 13:55:22",
"slot": "D",
"item_date": "2021-05-19"
},
{
"schedule_time": "2021-05-19 16:09:15",
"slot": "L",
"item_date": "2021-05-20"
},
{
"schedule_time": "2021-05-19 16:11:55",
"slot": "L",
"item_date": "2021-05-20"
},
I want to create a function that will take item_date and it will show how many schedules are between 9am to 12am. 12am to 3pm, 3pm to 6pm, 6pm to 9pm on previous days. if you look at the database the item_date and schedule_date are not the same. That’s why I want the previous day’s schedules listed in an array.
I have created a function it’s only returning 9am to 12am data. I want the schedules together in an array.
function schedulesList (date){
let dbItemDate = date;
let otherDayArray = schedules.filter(num => num.item_date !== dbItemDate); // not equal because I want other dates schedules not the exact date
let times = otherDayArray?.filter(num => num.schedule_time.split(' ')[1] >= '12:00:00' && num.schedule_time.split(' ')[1] <= '14:00:00');
console.log('9am to 12pm', times.length, 'schedules') //
}