# filter between two dates via a dataset

**URL:** <https://forum.wixstudio.com/t/filter-between-two-dates-via-a-dataset/28300>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [April 5, 2020, 4:32pm UTC](https://forum.wixstudio.com/t/filter-between-two-dates-via-a-dataset/28300 "2020-04-05T16:32:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephenmccall](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/stephenmccall/32/1773_2.png) [@stephenmccall](https://forum.wixstudio.com/u/stephenmccall)\
**Post date:** [April 5, 2020, 4:32pm UTC](https://forum.wixstudio.com/t/filter-between-two-dates-via-a-dataset/28300/1 "2020-04-05T16:32:45Z")

</div>

Hi team,

I have some code that seems to be working but not fully as expected.

The code works, but doesn’t filter between the dates, it seems to display any item that has a date either with a date greater or less than (so all items .ge) as apposed to between those two search terms

Anyone able to help?

```javascript
export function searchButton_click(event ) {
filter($w("#courseStartDate").value, $w('#endDate').value);
}

```

```javascript
function filter( startDate, endDate) {
let newFilter = wixData.filter();
console.log(newFilter)

if (startDate) newFilter = newFilter.ge('dateOne', startDate).or(newFilter.ge('dateTwo', startDate).or(newFilter.ge('dateThree', startDate))));

if (endDate) newFilter = newFilter.le('dateOne', endDate).or(newFilter.le('dateTwo', endDate).or(newFilter.le('dateThree', endDate))));

$w('#coursesDataset').setFilter(newFilter).then(() => {
let textVariable = $w('#coursesDataset').getTotalCount();
lastFilterSearchBox = searchBox;

})

}

```

Thank you 🙂

---

<div class="post-metadata">

**Author:** ![stephenmccall](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/stephenmccall/32/1773_2.png) [@stephenmccall](https://forum.wixstudio.com/u/stephenmccall)\
**Post date:** [April 11, 2020, 11:48am UTC](https://forum.wixstudio.com/t/filter-between-two-dates-via-a-dataset/28300/2 "2020-04-11T11:48:11Z")

</div>

Anyone?

---

<div class="post-metadata">

**Author:** ![tony-brunsman](https://avatars.discourse-cdn.com/v4/letter/t/ea5d25/32.png) [@tony-brunsman](https://forum.wixstudio.com/u/tony-brunsman)\
**Post date:** [April 11, 2020, 7:15pm UTC](https://forum.wixstudio.com/t/filter-between-two-dates-via-a-dataset/28300/3 "2020-04-11T19:15:34Z")

</div>

Hi Stephen,

Date range filters can be pretty tricky, especially one like what you have - taking into consideration three different dates. You have to account for any possible dateTime value for a given date. To do that, the startDate and endDate needs to be modified.

```javascript
export function filter(startDate,endDate){
   let yearValue = startDate.getFullYear();
   let monthValue = startDate.getMonth();
   let dayValue = startDate.getDate();
   let date1 = new Date(yearValue,monthValue,dayValue,0,0,0);
   yearValue = endDate.getFullYear();
   monthValue = endDate.getMonth();
   dayValue = endDate.getDate();
   let date2=new Date(yearValue,monthValue,dayValue,23,59,59);
   $w("#coursesDataset").setFilter(wixData.filter()
   .between("dateOne",date1,date2)
   .or(
   wixData.filter()
   .between("dateTwo",date1,date2)
   )
   .or(
   wixData.filter()
   .between("dateThree",date1,date2)
   )
   )
   .then(() => {
     console.log("Filtered!");
   });
}

```

---

<div class="post-metadata">

**Author:** ![stephenmccall](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/stephenmccall/32/1773_2.png) [@stephenmccall](https://forum.wixstudio.com/u/stephenmccall)\
**Post date:** [April 12, 2020, 7:34am UTC](https://forum.wixstudio.com/t/filter-between-two-dates-via-a-dataset/28300/4 "2020-04-12T07:34:55Z")

</div>

@tony-brunsman this works well, thank you. I had been playing with similar code yesterday but not using .between and this made sense once I started to play with and modify for my use.

Thanks again and have a great day!
