# "Calculated" date field and Timezone problem

**URL:** <https://discuss.elastic.co/t/calculated-date-field-and-timezone-problem/105851>\
**Category:** Logstash\
**Created:** [October 31, 2017, 9:00am UTC](https://discuss.elastic.co/t/calculated-date-field-and-timezone-problem/105851 "2017-10-31T09:00:56Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Anabella\_Cristaldi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anabella_cristaldi/32/23612_2.png) [@Anabella\_Cristaldi](https://discuss.elastic.co/u/Anabella_Cristaldi)\
**Post date:** [October 31, 2017, 9:00am UTC](https://discuss.elastic.co/t/calculated-date-field-and-timezone-problem/105851/1 "2017-10-31T09:00:57Z")

</div>

Hi all,

I'm parsing some phone call logs that have a start timestamp and a duration. And I need to calculate the timestamp where the call ends. That is _ **Start\_timestamp + duration** _.

The date in the original log is in this format yyyyMMddHHmmss (20171005072911) and I'm able to convert it to date using the date plugin and set the localtimezone with success

```
date {
        match => ["ts", "yyyyMMddHHmmss"]
        timezone => "Europe/Madrid"
        remove_field => ["ts"]
}

```

For the example abovem I get `@timestamp:October 5th 2017, 07:29:11.000` which is correct.

In order to calculate the timestamp for the STOP I use the ruby plugin

```
  if [duration]{
                ruby {
                        code =>"event.set('ts_stop',(event.get('@timestamp')+event.get('duration')))"
                }
        }

```

The result is correct but I'm not able to get the new field with the local tz but UTC

`ts_stop:2017-10-05T05:29:11.000Z`

There is any way to obtain the ts\_stop with my local timezone?

Thannk you very much  
Regards  
Ana

---

<div class="post-metadata">

**Author:** ![Anabella\_Cristaldi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anabella_cristaldi/32/23612_2.png) [@Anabella\_Cristaldi](https://discuss.elastic.co/u/Anabella_Cristaldi)\
**Post date:** [October 31, 2017, 1:21pm UTC](https://discuss.elastic.co/t/calculated-date-field-and-timezone-problem/105851/2 "2017-10-31T13:21:06Z")

</div>

I found a solution, probably not the best but it works.

```
.....
        date {
                match => ["ts", "yyyyMMddHHmmss"]
                timezone => "Europe/Andorra"
                remove_field => ["ts"]
        }
        mutate {
                convert => { "duration" => "integer" }
        }
        if [duration]{
                ruby {
                        code => "event.set('ts_temp',event.get('@timestamp')+event.get('duration'))"
                }
                ruby {
                        code => "event.set('ts_stop',event.get('ts_temp').time.localtime.strftime('%d/%b/%Y:%H:%M:%S CST'))"
                        remove_field => ["ts_temp"]
                }

        }

....

```

So first I compute the stop timestamp and then I set the CST timezone.

If there is any suggestion about how to improve this It would be appreciated  
Regards  
Anna

---

<div class="post-metadata">

**Author:** ![Anabella\_Cristaldi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/anabella_cristaldi/32/23612_2.png) [@Anabella\_Cristaldi](https://discuss.elastic.co/u/Anabella_Cristaldi)\
**Post date:** [October 31, 2017, 3:04pm UTC](https://discuss.elastic.co/t/calculated-date-field-and-timezone-problem/105851/3 "2017-10-31T15:04:47Z")

</div>

Not really solved, the new field "ts\_stop" it is not date type

```
 "ts_stop": {
    "type": "text",
    "fields": {
      "keyword": {
        "type": "keyword",
        "ignore_above": 256
      }
    }
  },
```

---

<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:** [November 28, 2017, 3:05pm UTC](https://discuss.elastic.co/t/calculated-date-field-and-timezone-problem/105851/4 "2017-11-28T15:05:14Z")

</div>

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