# How to compare date in Logstash?

**URL:** https://discuss.elastic.co/t/how-to-compare-date-in-logstash/32250
**Category:** Logstash
**Created:** [October 15, 2015, 9:00am UTC](https://discuss.elastic.co/t/how-to-compare-date-in-logstash/32250 "2015-10-15T09:00:46Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![RohanKumbhar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rohankumbhar/32/23649_2.png) [@RohanKumbhar](https://discuss.elastic.co/u/RohanKumbhar)
#### Post date: [October 15, 2015, 9:00am UTC](https://discuss.elastic.co/t/how-to-compare-date-in-logstash/32250/1 "2015-10-15T09:00:46Z")

</div>

Hi All,

There is one requirement where i need to compare log date with some constant date. and then perform indexing in ES.

is there any way where i can compare two dates in logstash?

Thanks,  
Rohan

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [October 15, 2015, 9:07am UTC](https://discuss.elastic.co/t/how-to-compare-date-in-logstash/32250/2 "2015-10-15T09:07:58Z")

</div>

You can use the date filter to create a field with an ISO8601 date, and that date can be compared to another ISO8601 in a conditional.

---

<div class="post-metadata">

### Author: ![OrangeDog](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/orangedog/32/4630_2.png) [@OrangeDog](https://discuss.elastic.co/u/OrangeDog)
#### Post date: [May 5, 2017, 4:00pm UTC](https://discuss.elastic.co/t/how-to-compare-date-in-logstash/32250/3 "2017-05-05T16:00:48Z")

</div>

But what's the syntax for that? Things like this give "undefined method `time'" exceptions.

```
if [@timestamp] > "2017-01-01T00:00:00Z"
```

---

<div class="post-metadata">

### Author: ![seth.yes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/seth.yes/32/11788_2.png) [@seth.yes](https://discuss.elastic.co/u/seth.yes)
#### Post date: [May 5, 2017, 5:01pm UTC](https://discuss.elastic.co/t/how-to-compare-date-in-logstash/32250/4 "2017-05-05T17:01:12Z")

</div>

There's a Date plugin for logstash you can use where you give it the syntax to expect for the time.

[https://www.elastic.co/guide/en/logstash/current/plugins-filters-date.html](https://www.elastic.co/guide/en/logstash/current/plugins-filters-date.html)

---

<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: [July 6, 2017, 4:26am UTC](https://discuss.elastic.co/t/how-to-compare-date-in-logstash/32250/5 "2017-07-06T04:26:46Z")

</div>


