# Convert YYYY-MM-DD-HH.MM.SS to date

**URL:** <https://discuss.elastic.co/t/convert-yyyy-mm-dd-hh-mm-ss-to-date/293820>\
**Category:** Logstash\
**Created:** [January 9, 2022, 8:05am UTC](https://discuss.elastic.co/t/convert-yyyy-mm-dd-hh-mm-ss-to-date/293820 "2022-01-09T08:05:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hooman24](https://avatars.discourse-cdn.com/v4/letter/h/82dd89/32.png) [@Hooman24](https://discuss.elastic.co/u/Hooman24)\
**Post date:** [January 9, 2022, 8:05am UTC](https://discuss.elastic.co/t/convert-yyyy-mm-dd-hh-mm-ss-to-date/293820/1 "2022-01-09T08:05:20Z")

</div>

Hi  
I have a dateTime field with the following format:

yyyy-mm-dd-HH.mm.ss

I want to use this field as a date time field in ELK. I don't know how to change 11th position of the string('-') to 'T' to convert this field into yyyy-mm-ddThh-mm-ss format.

I'm new to logstash, I didn't find anything for string manipulation or position based replace.

---

<div class="post-metadata">

**Author:** ![leandrojmp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/leandrojmp/32/107231_2.png) [@leandrojmp](https://discuss.elastic.co/u/leandrojmp)\
**Post date:** [January 9, 2022, 3:41pm UTC](https://discuss.elastic.co/t/convert-yyyy-mm-dd-hh-mm-ss-to-date/293820/2 "2022-01-09T15:41:25Z")

</div>

You just need to pass your pattern to the [date filter](https://www.elastic.co/guide/en/logstash/current/plugins-filters-date.html).

Try this:

```auto
date {
  match => ["dateTime", "yyyy-MM-dd-HH.mm.ss"]
}

```

---

<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:** [January 9, 2022, 4:24pm UTC](https://discuss.elastic.co/t/convert-yyyy-mm-dd-hh-mm-ss-to-date/293820/3 "2022-01-09T16:24:14Z")

</div>

Using a date filter is probably the best solution, but to answer your question you can use

```
mutate { gsub => ["dateTimeField", "^.{10}-", "\1T"] }

```

to change the 11th character from - to T

---

<div class="post-metadata">

**Author:** ![Hooman24](https://avatars.discourse-cdn.com/v4/letter/h/82dd89/32.png) [@Hooman24](https://discuss.elastic.co/u/Hooman24)\
**Post date:** [January 10, 2022, 5:34am UTC](https://discuss.elastic.co/t/convert-yyyy-mm-dd-hh-mm-ss-to-date/293820/4 "2022-01-10T05:34:14Z")

</div>

Thank you @leandrojmp. It works.

---

<div class="post-metadata">

**Author:** ![Hooman24](https://avatars.discourse-cdn.com/v4/letter/h/82dd89/32.png) [@Hooman24](https://discuss.elastic.co/u/Hooman24)\
**Post date:** [January 10, 2022, 5:35am UTC](https://discuss.elastic.co/t/convert-yyyy-mm-dd-hh-mm-ss-to-date/293820/5 "2022-01-10T05:35:20Z")

</div>

@Badger I really need this regex syntax for string manipulation. Thank you.

---

<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:** [February 7, 2022, 5:35am UTC](https://discuss.elastic.co/t/convert-yyyy-mm-dd-hh-mm-ss-to-date/293820/6 "2022-02-07T05:35:24Z")

</div>

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