# How to change date format in logstash

**URL:** <https://discuss.elastic.co/t/how-to-change-date-format-in-logstash/277642>\
**Category:** Logstash\
**Created:** [July 2, 2021, 11:35am UTC](https://discuss.elastic.co/t/how-to-change-date-format-in-logstash/277642 "2021-07-02T11:35:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rknd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rknd/32/103882_2.png) [@rknd](https://discuss.elastic.co/u/rknd)\
**Post date:** [July 2, 2021, 11:35am UTC](https://discuss.elastic.co/t/how-to-change-date-format-in-logstash/277642/1 "2021-07-02T11:35:31Z")

</div>

I have a logs like below;

```auto
04/12/2020 5:12:56 PM
05/12/2020 6:13:36 AM

```

I want to match this fields and change to this format in below;

```auto
2020-12-04 17:12:56
2020-12-04 06:13:36

```

How can i do this in logstash ?

Thanks for answering

---

<div class="post-metadata">

**Author:** ![ritchierich](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ritchierich/32/4329_2.png) [@ritchierich](https://discuss.elastic.co/u/ritchierich)\
**Post date:** [July 2, 2021, 8:01pm UTC](https://discuss.elastic.co/t/how-to-change-date-format-in-logstash/277642/2 "2021-07-02T20:01:04Z")

</div>

Checkout the [Logstash Date Filter Plugin](https://www.elastic.co/guide/en/logstash/current/plugins-filters-date.html) and [Joda-Time](https://www.joda.org/joda-time/key_format.html) for more working with Dates.

If you want to experiment more time to fine tune your results, give this try:

```auto
input {
  generator {
    message => '{"my_date": "04/12/2020 5:12:56 PM" }'
    count => 2
  }

  generator {
    message => '{"my_date": "05/12/2020 6:13:36 AM" }'
    count => 2
  }
 
}
filter {
  json { 
    source => "message" 
  }

  date {
    match => ["my_date", "dd/MM/YYYY hh:mm:ss a"]
    timezone =>"UTC"
    target => ["@timestamp"]
  }
}
output { 
  stdout { 
    codec => rubydebug 
  } 
}

```

Results:

```auto
{
      "@version" => "1",
       "my_date" => "05/12/2020 6:13:36 AM",
      "sequence" => 0,
    "@timestamp" => 2020-12-05T06:13:36.000Z,
       "message" => "{\"my_date\": \"05/12/2020 6:13:36 AM\" }",
          "host" => "3af2031542b8"
}
{
      "@version" => "1",
       "my_date" => "04/12/2020 5:12:56 PM",
      "sequence" => 1,
    "@timestamp" => 2020-12-04T17:12:56.000Z,
       "message" => "{\"my_date\": \"04/12/2020 5:12:56 PM\" }",
          "host" => "3af2031542b8"
}
{
      "@version" => "1",
       "my_date" => "04/12/2020 5:12:56 PM",
      "sequence" => 0,
    "@timestamp" => 2020-12-04T17:12:56.000Z,
       "message" => "{\"my_date\": \"04/12/2020 5:12:56 PM\" }",
          "host" => "3af2031542b8"
}
{
      "@version" => "1",
       "my_date" => "05/12/2020 6:13:36 AM",
      "sequence" => 1,
    "@timestamp" => 2020-12-05T06:13:36.000Z,
       "message" => "{\"my_date\": \"05/12/2020 6:13:36 AM\" }",
          "host" => "3af2031542b8"
}

```

Let me know if this helps.

---

<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 30, 2021, 8:01pm UTC](https://discuss.elastic.co/t/how-to-change-date-format-in-logstash/277642/3 "2021-07-30T20:01:24Z")

</div>

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