# Painless time comparison

**URL:** <https://discuss.elastic.co/t/painless-time-comparison/66460>\
**Category:** Elasticsearch\
**Created:** [November 17, 2016, 9:57pm UTC](https://discuss.elastic.co/t/painless-time-comparison/66460 "2016-11-17T21:57:33Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ndev](https://avatars.discourse-cdn.com/v4/letter/n/71e660/32.png) [@ndev](https://discuss.elastic.co/u/ndev)\
**Post date:** [November 17, 2016, 9:57pm UTC](https://discuss.elastic.co/t/painless-time-comparison/66460/1 "2016-11-17T21:57:33Z")

</div>

I'm attempting to write a script that allows me to find the number of events that are still active. My attempt so far this is not working is below:

```
int total = 0;
def n = 323423L;

if(doc['startTime'][0] < n && doc['endTime'][0] > n)
{
    total = 1;
}

return total;

```

What I wish to have is for n to be the current time, and if the start is less than, and the end is greater than, set the total equal to 1.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 15, 2016, 9:57pm UTC](https://discuss.elastic.co/t/painless-time-comparison/66460/2 "2016-12-15T21:57:51Z")

</div>

Closed on December 15, 2016, 9:57pm UTC

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