# Search dataset between two dates

**URL:** <https://forum.wixstudio.com/t/search-dataset-between-two-dates/30636>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [March 23, 2020, 6:42am UTC](https://forum.wixstudio.com/t/search-dataset-between-two-dates/30636 "2020-03-23T06:42:59Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mariannepenanueva](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mariannepenanueva/32/17722_2.png) [@mariannepenanueva](https://forum.wixstudio.com/u/mariannepenanueva)\
**Post date:** [March 23, 2020, 6:42am UTC](https://forum.wixstudio.com/t/search-dataset-between-two-dates/30636/1 "2020-03-23T06:42:59Z")

</div>

If I would input two dates, how can I get the results between those dates from the dataset and display it to a table?

The date is on one field of the dataset and I would like to display only 5 fields on the table (5 columns) instead of all fields on the dataset.

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [March 23, 2020, 9:12am UTC](https://forum.wixstudio.com/t/search-dataset-between-two-dates/30636/2 "2020-03-23T09:12:01Z")

</div>

You can set a filter using [.ge()](https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html#ge) for the start date and [.le()](https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html#le) for the end date. The filter will result in all items between (and including) both of those dates. Something like this:

```javascript
import wixData from 'wix-data';

// ...

wixData.query("myCollection")
  .ge("date", startDate) // you need to set startDate
  .le("date", endDate) // you need to set endDate
  .find()
  .then( (results) => {
    if(results.items.length > 0) {
        // do stuff with the results
    } else {
      // handle case where no matching items found
    }
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

```

---

<div class="post-metadata">

**Author:** ![mariannepenanueva](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mariannepenanueva/32/17722_2.png) [@mariannepenanueva](https://forum.wixstudio.com/u/mariannepenanueva)\
**Post date:** [March 25, 2020, 1:42pm UTC](https://forum.wixstudio.com/t/search-dataset-between-two-dates/30636/3 "2020-03-25T13:42:23Z")

</div>

I add this one and it didn’t work, I don’t know how to filter the dataset after the query.

```javascript
if(results.items.length > 0) {
$w('#manuListDataset').setFilter();
}

```

---

<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 10, 2020, 4:57pm UTC](https://forum.wixstudio.com/t/search-dataset-between-two-dates/30636/4 "2020-04-10T16:57:28Z")

</div>

Hi @yisrael-wix

I was wondering if you would be able to help with the code above but for multiple fields?

i.e.

```javascript
wixData.query("myCollection")
  .ge("date", startDate).or("dateTwo, startDate).or("dateThree", startDate)
  .le("date", endDate).or("dateTwo", startDate).or("dateThree", startDate)  
  .find()
  .then( (results) => {
    if(results.items.length > 0) {
        // do stuff with the results
    } else {
      // handle case where no matching items found
    }
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

```

Thank you and I hope you keeping safe and well 🙂

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [April 12, 2020, 7:26am UTC](https://forum.wixstudio.com/t/search-dataset-between-two-dates/30636/5 "2020-04-12T07:26:45Z")

</div>

@stephenmccall Not really clear what you are trying to do, and why, but you should look at the [.or() API docs](https://www.wix.com/corvid/reference/wix-data.WixDataQuery.html#or) for the correct usage of **.or()**.

---

<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:52am UTC](https://forum.wixstudio.com/t/search-dataset-between-two-dates/30636/6 "2020-04-12T07:52:56Z")

</div>

Hi @yisrael-wix ,

Thanks for the info, I did a little reading up over the past 3 days and with a little help managed to get this working. I just have a slight issue with some code (related) that I’m working through at the moment. Thanks again and here is the code for anyone who wants to search BETWEEN two dates via a variety of fields in the database.

I presume there must be a slicker way Yisreal? I haven’t put all the code but I’m actually queering 12 date fields which seems inefficient but after 3 days it’ll do just fine!

```javascript
let startDate = $w('#datePicker1').value;
let endDate = $w('#datePicker2').value;

let yearValue = startDate.getFullYear();
let monthValue = startDate.getMonth();
let dayValue = startDate.getDate();
let startDateSrch = new Date(yearValue, monthValue, dayValue, 0, 0, 0);

yearValue = endDate.getFullYear();
monthValue = endDate.getMonth();
dayValue = endDate.getDate();
let endDateSrch = new Date(yearValue, monthValue, dayValue, 23, 59, 59);

wixData.query("CourseItems")
.between('dateOne', startDateSrch, endDateSrch)
.or(wixData.query().between('dateTwo', startDateSrch, endDateSrch))
.or(wixData.query().between('dateThree', startDateSrch, endDateSrch))
.find()
  .then( (results) => {
    if(results.items.length > 0) {
        // do stuff with the results
    } else {
      // handle case where no matching items found
    }
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

```

---

<div class="post-metadata">

**Author:** ![daniel25263](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/daniel25263/32/25927_2.png) [@daniel25263](https://forum.wixstudio.com/u/daniel25263)\
**Post date:** [May 14, 2021, 1:54pm UTC](https://forum.wixstudio.com/t/search-dataset-between-two-dates/30636/7 "2021-05-14T13:54:22Z")

</div>

Does this work querying the collections \_createdDate field ?
