'how can I make a function which will return a number of Schedule Dates that are matching with other Item_date from my database

I want to create a function where Item_date will be received from my Database and will return a number of Schedule Dates that are matching with other Item_date.

For instance, I can select 2021-05-20, and the function will return :

19th November: 2 Scheduled

18th November: 2 Scheduled

Can anyone give me an idea of how can I make it?

This is my database example:

[
    {
        "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"
    },...

]


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source