# Issues with between

**URL:** <https://discuss.elastic.co/t/issues-with-between/185750>\
**Category:** Logstash\
**Created:** [June 14, 2019, 2:23am UTC](https://discuss.elastic.co/t/issues-with-between/185750 "2019-06-14T02:23:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harshet\_Jain](https://avatars.discourse-cdn.com/v4/letter/h/dc4da7/32.png) [@Harshet\_Jain](https://discuss.elastic.co/u/Harshet_Jain)\
**Post date:** [June 14, 2019, 2:23am UTC](https://discuss.elastic.co/t/issues-with-between/185750/1 "2019-06-14T02:23:26Z")

</div>

I am using the following ruby code but getting an exception about "ruby exception undefined method between? for nil:Nilclass"?

`event.set("[weekInMonth]", 2) if event.get("[tempDay]").between?(8, 15)`

What should I change this to? I am trying to use this for multiple things.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [June 14, 2019, 1:19pm UTC](https://discuss.elastic.co/t/issues-with-between/185750/2 "2019-06-14T13:19:36Z")

</div>

That suggests that some events do not have a tempDay field.

---

<div class="post-metadata">

**Author:** ![Harshet\_Jain](https://avatars.discourse-cdn.com/v4/letter/h/dc4da7/32.png) [@Harshet\_Jain](https://discuss.elastic.co/u/Harshet_Jain)\
**Post date:** [July 9, 2019, 7:38am UTC](https://discuss.elastic.co/t/issues-with-between/185750/3 "2019-07-09T07:38:41Z")

</div>

Is there any way to modify the ruby so it does not give the error. For example, if nil then skip.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [July 9, 2019, 1:04pm UTC](https://discuss.elastic.co/t/issues-with-between/185750/4 "2019-07-09T13:04:22Z")

</div>

```
code => '
    t = event.get("[tempDay]")
    if t
        event.set("[weekInMonth]", 2) if t.between?(8, 15)
    end
'
```

---

<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:** [August 6, 2019, 1:04pm UTC](https://discuss.elastic.co/t/issues-with-between/185750/5 "2019-08-06T13:04:30Z")

</div>

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