# Converting date format in logstash

**URL:** <https://discuss.elastic.co/t/converting-date-format-in-logstash/137026>\
**Category:** Logstash\
**Created:** [June 22, 2018, 1:13pm UTC](https://discuss.elastic.co/t/converting-date-format-in-logstash/137026 "2018-06-22T13:13:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Melvin\_Moses](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@Melvin\_Moses](https://discuss.elastic.co/u/Melvin_Moses)\
**Post date:** [June 22, 2018, 1:13pm UTC](https://discuss.elastic.co/t/converting-date-format-in-logstash/137026/1 "2018-06-22T13:13:09Z")

</div>

I have to extract a date from a log file, need to convert it to another date format and save it to Elasticsearch. My logstash code is like this

> filter {  
> grok{  
> patterns\_dir =\> "./patterns"  
> match =\> ["message", "%{pattern:timestamp} %{GREEDYDATA:message}"]  
> }  
> }

My log file is like this

> 20-Jun-2018 11:08:22.137 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version: Apache Tomcat/8.5.31

What I want is I need to change the **timestamp** into another timezone and save it to Elasticsearch. Any help would be appreciable.

---

<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 22, 2018, 2:27pm UTC](https://discuss.elastic.co/t/converting-date-format-in-logstash/137026/2 "2018-06-22T14:27:35Z")

</div>

Try

```
    dissect {
        mapping => { "message" => "%{ts} %{+ts} %{restOfLine}" }
    }
    date { match => ["ts", "dd-MMM-yyyy YY:mm:ss.SSS"] timezone => "Europe/Moscow" }

```

Note that all dates in elasticsearch are stored as UTC.

---

<div class="post-metadata">

**Author:** ![Melvin\_Moses](https://avatars.discourse-cdn.com/v4/letter/m/7ba0ec/32.png) [@Melvin\_Moses](https://discuss.elastic.co/u/Melvin_Moses)\
**Post date:** [June 25, 2018, 4:54am UTC](https://discuss.elastic.co/t/converting-date-format-in-logstash/137026/3 "2018-06-25T04:54:56Z")

</div>

> [@Badger](#):
>
> dd-MMM-yyyy YY:mm:ss.SSS

What I want is not to change the timezone, but to change the time format like

> dd-MMM-yyyy YY:mm:ss.SSS to yyy-MMM-dd YY:mm:ss.SSS

I have mapped my time index in Elasticsearch as like follows

> PUT application\_log  
> {"mappings": {  
> "doc": {  
> "properties": {
> 
> ```
> "timestamp": {
> "type": "date",
> "format": "dd-MMM-yyyy HH:mm:ss.SSS"
> }
> }
> }
> }
> }
> }
> 
> ```
> 
> }  
> }

so I need to convert the date format from logstash

---

<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 23, 2018, 4:54am UTC](https://discuss.elastic.co/t/converting-date-format-in-logstash/137026/4 "2018-07-23T04:54:58Z")

</div>

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