# Global variable?

**URL:** <https://discuss.elastic.co/t/global-variable/96794>\
**Category:** Logstash\
**Created:** [August 11, 2017, 3:24pm UTC](https://discuss.elastic.co/t/global-variable/96794 "2017-08-11T15:24:57Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Chemse](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chemse/32/17956_2.png) [@Chemse](https://discuss.elastic.co/u/Chemse)\
**Post date:** [August 14, 2017, 9:53am UTC](https://discuss.elastic.co/t/global-variable/96794/2 "2017-08-14T09:53:06Z")

</div>

I’ve tried this code but it doesn’t work

```
date {
        match => ["period1","dd/MM/YYYY"]
        target=> "period1"
    }
    date {
        match => ["period2","dd/MM/YYYY"]
        target=> "period2"
   }
   ruby {
        code => "event.set('period', (event.get('period2') - event.get('period1'))/3600/24)"

   }
   ruby{
               code => "$my_var " = "%{peroid}" 
       }

```

I want to use the value of $my\_var as a condition for an other event (next line)

---

_[View the full topic](https://discuss.elastic.co/t/global-variable/96794)._
