# API - Filter by date

**URL:** <https://discourse.getcockpit.com/t/api-filter-by-date/2001>\
**Category:** Support\
**Created:** [July 14, 2021, 3:21pm UTC](https://discourse.getcockpit.com/t/api-filter-by-date/2001 "2021-07-14T15:21:25Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![abernh](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.getcockpit.com/abernh/32/859_2.png) [@abernh](https://discourse.getcockpit.com/u/abernh)\
**Post date:** [July 17, 2021, 6:14pm UTC](https://discourse.getcockpit.com/t/api-filter-by-date/2001/10 "2021-07-17T18:14:28Z")

</div>

Given the operator works at some point it seems there is another way to filter by range:

> [@Get entries with range?](https://discourse.getcockpit.com/t/get-entries-with-range/42/4):
>
> fetch('/api/collections/get/posts?token=xxtokenxx', { method: 'post', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ filter: { $and: [{myfield: {$gt: x}}, {myfield: {$lt: y}}] } }) }) .then(res=\>res.json()) .then(res =\> console.log(res));

This would make the query look like

```auto
/api/collections/entries/scans?filter[$and][][_created][$gte]=STARTTIME&filter[$and][][_created][$lte]=ENDTIME

```

Both variants work nicely for me in my LiteDb test setup.

---

_[View the full topic](https://discourse.getcockpit.com/t/api-filter-by-date/2001)._
