# Filter by DateTime

**URL:** <https://discuss.dgraph.io/t/filter-by-datetime/2318>\
**Category:** Users\
**Created:** [March 16, 2018, 12:22pm UTC](https://discuss.dgraph.io/t/filter-by-datetime/2318 "2018-03-16T12:22:45Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fendor](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/fendor/32/963_2.png) [@fendor](https://discuss.dgraph.io/u/fendor)\
**Post date:** [March 16, 2018, 12:22pm UTC](https://discuss.dgraph.io/t/filter-by-datetime/2318/1 "2018-03-16T12:22:45Z")

</div>

I am currently trying to work out how to compare datetimes with each other.  
The straight forward way of adding some Index seems not applicable for me, since I want to compare the DateTime accurately by minutes and sometimes even seconds.

The question is, is this currently even possible efficiently?

To provide an example of my use-case, consider the following query:

```auto
{
    query(func:uid(...)) @filter(le(createdAt, "2018-03-16T00:30:00Z")) { 
        uid
    }
}

```

with the schema:

```auto
createdAt: dateTime . 

```

I hope the example is semantically correct, however, this does not work because `createdAt` is not indexed.  
As far as I’ve seen, I can only index it by Year, Month, Day and Hour, but in this case, I want to retrieve only nodes, which are _really_ smaller than the given dateTime `2018-03-16T00:30:00Z`.

---

<div class="post-metadata">

**Author:** ![mrjn](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.dgraph.io/mrjn/32/775_2.png) [@mrjn](https://discuss.dgraph.io/u/mrjn)\
**Post date:** [March 17, 2018, 4:41pm UTC](https://discuss.dgraph.io/t/filter-by-datetime/2318/2 "2018-03-17T16:41:47Z")

</div>

They can be indexed by hour, yet still be compared at more granular levels. Hour index helps us narrow down the search field, but then we use normal comparisons to check if the entries in the search field match the query parameters.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex007/uploads/dgraph/original/2X/2/2b38fdece2abe5814f2e51bee69d1e67fc304b0a.png) [@system](https://discuss.dgraph.io/u/system)\
**Post date:** [April 16, 2018, 4:44pm UTC](https://discuss.dgraph.io/t/filter-by-datetime/2318/4 "2018-04-16T16:44:37Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
