# Unable to change date format

**URL:** <https://discuss.elastic.co/t/unable-to-change-date-format/295948>\
**Category:** Logstash\
**Created:** [February 1, 2022, 1:53pm UTC](https://discuss.elastic.co/t/unable-to-change-date-format/295948 "2022-02-01T13:53:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![duanra22](https://avatars.discourse-cdn.com/v4/letter/d/3ec8ea/32.png) [@duanra22](https://discuss.elastic.co/u/duanra22)\
**Post date:** [February 1, 2022, 1:53pm UTC](https://discuss.elastic.co/t/unable-to-change-date-format/295948/1 "2022-02-01T13:53:31Z")

</div>

Hello everyone,

I've seen several topics with the same problem, however none of the solutions I found worked for me and it's making me crazy because I am sure it should be very simple.

To explain the problem, I am using a ruby filter to extract data from a long line based on where the information is on the line and one of these data is a datetime.  
For example :

`event.set('[heading][date]', event.get('[message]')[1526..1544])`

Hewever, this makes the following output with this format:

> "heading": {  
> "date": "2022-02-01-00.00.00"  
> }

I want it to be in this format : `"date": "2022-02-01T00:00:00.000Z"` (the same as @timestamp)  
I tried to use date filter or strftime in ruby but I can't make it work.

Thanks for your help and sorry if I should have find in other topics

---

<div class="post-metadata">

**Author:** ![Tomo\_M](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@Tomo\_M](https://discuss.elastic.co/u/Tomo_M)\
**Post date:** [February 1, 2022, 2:43pm UTC](https://discuss.elastic.co/t/unable-to-change-date-format/295948/2 "2022-02-01T14:43:12Z")

</div>

This topic must be about Logstash.

ruby filter and date filter worked fine for me.

```auto

input {
  generator {
      lines => [
          "2022-02-01-00.00.00",
          "2022-02-01-00.00.00Z"
      ]
      count => 1
  }
}
filter{
    ruby {
        code => "
            event.set('[datestr]', event.get('[message]')[0..18])
        "
    }
    date {
        match => ["datestr", "yyyy-MM-dd-HH.mm.ss"]
        target => "datetime"
        timezone => "Asia/Tokyo"
    }
}
output {
    stdout {
        codec => rubydebug{metadata => false}
    }
}

```

---

<div class="post-metadata">

**Author:** ![duanra22](https://avatars.discourse-cdn.com/v4/letter/d/3ec8ea/32.png) [@duanra22](https://discuss.elastic.co/u/duanra22)\
**Post date:** [February 1, 2022, 2:53pm UTC](https://discuss.elastic.co/t/unable-to-change-date-format/295948/3 "2022-02-01T14:53:13Z")

</div>

Sorry for the mistake I juste changed it.

Thanks for your reply I will try this and keep you updated !

---

<div class="post-metadata">

**Author:** ![duanra22](https://avatars.discourse-cdn.com/v4/letter/d/3ec8ea/32.png) [@duanra22](https://discuss.elastic.co/u/duanra22)\
**Post date:** [February 1, 2022, 3:05pm UTC](https://discuss.elastic.co/t/unable-to-change-date-format/295948/4 "2022-02-01T15:05:05Z")

</div>

Thanks @Tomo_M it works fine ! I guess it was just a mistake in the date format in my filter ☹

---

<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:** [March 1, 2022, 3:05pm UTC](https://discuss.elastic.co/t/unable-to-change-date-format/295948/5 "2022-03-01T15:05:50Z")

</div>

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