Skip to content
Advertisement

Creating date range for each loop in a date object array in js

I am currently working on a dropdown filter that lets the user choose between a period of time in where he can select either daily, weekly, monthly and yearly. I manage to create the daily filter but on the weekly, monthly and yearly bases I am having issues with the start and end date that I need to consider each for each loop.

As a sample, let say that I have this object.

JavaScript

So after going through each date, I want to create a range that includes the start date and an end date before the next element. Here is an example of what I am trying to get.

JavaScript

In summary, I want to create a date range for each date element in an object that has gaps in between. I will be using the created date range of each loop to fetch the data from the db that is inside the date range. Thank you in advance

I have no idea what to do here.

Advertisement

Answer

What I would go for, is to compute daily/weekly/monthly/yearly ranges. Your select values would be daily/weekly/monthly/yearly and according to the selected value, you would use the corresponding range to filter information

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement