# How to format, yyyymmdd to yyyy-mm-dd in a log file?

**URL:** https://discuss.elastic.co/t/how-to-format-yyyymmdd-to-yyyy-mm-dd-in-a-log-file/58666
**Category:** Logstash
**Created:** [August 23, 2016, 10:18am UTC](https://discuss.elastic.co/t/how-to-format-yyyymmdd-to-yyyy-mm-dd-in-a-log-file/58666 "2016-08-23T10:18:12Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Kulasangar\_Gowrisang](https://avatars.discourse-cdn.com/v4/letter/k/ce73a5/32.png) [@Kulasangar\_Gowrisang](https://discuss.elastic.co/u/Kulasangar_Gowrisang)
#### Post date: [August 23, 2016, 10:18am UTC](https://discuss.elastic.co/t/how-to-format-yyyymmdd-to-yyyy-mm-dd-in-a-log-file/58666/1 "2016-08-23T10:18:13Z")

</div>

I've started working around with the ELK tool stack since few weeks. What I need is to get the **timestamp** of the log event which includes date and the time and show it in a different field (ie: log\_timestamp). I've tried pulling out all the options for the **Datestamp** , but nothing worked. This is a line of the log file which I have.

"20160805 00:00:01.296,GetProvisioning,3,W1oOOW8oj58GhglVjVNg0Ssl4CXA1P,50219--1958335734-1470326399706,SUCCESS,GetProvisioningTransactionId-01223,null,W1oOOW8oj58GhglVjVNg0Ssl4CXA1P,en,CELCOM\_MY\_DCB  
"  
I need to format the date of the log event as **yyyy-mm-dd** since i'm unable to use the "Date" grok filters. Or is there a way that I can filter it out with the above **yyyymmdd** date format which is originally there in the log file?

Any help would be appreciated.

---

<div class="post-metadata">

### Author: ![m0n0lith](https://avatars.discourse-cdn.com/v4/letter/m/f4b2a3/32.png) [@m0n0lith](https://discuss.elastic.co/u/m0n0lith)
#### Post date: [August 23, 2016, 10:52am UTC](https://discuss.elastic.co/t/how-to-format-yyyymmdd-to-yyyy-mm-dd-in-a-log-file/58666/2 "2016-08-23T10:52:01Z")

</div>

You could make your own version of "SYSLOGTIMESTAMP". And have that added to 'timestamp' and then do a 'date {}' on it.  
Something like:  
`OWNTIMESTAMP %{YEAR}%{MONTHNUM}%{MONTHDAY} %{TIME}`  
And use it in grok like:  
`grok { patterns_dir => "/path/to/own-patterns/" match => ["message", "%{OWNTIMESTAMP:timestamp},%{GREEDYDATA:rest_message}"] } date { match => ["timestamp", "yyyyMMdd HH:mm:ss"] }`  
You can add multiple date matches. And if you like mutate to the format you want.

---

<div class="post-metadata">

### Author: ![Kulasangar\_Gowrisang](https://avatars.discourse-cdn.com/v4/letter/k/ce73a5/32.png) [@Kulasangar\_Gowrisang](https://discuss.elastic.co/u/Kulasangar_Gowrisang)
#### Post date: [August 23, 2016, 11:04am UTC](https://discuss.elastic.co/t/how-to-format-yyyymmdd-to-yyyy-mm-dd-in-a-log-file/58666/3 "2016-08-23T11:04:44Z")

</div>

Thank you, it works.

---

<div class="post-metadata">

### Author: ![Kulasangar\_Gowrisang](https://avatars.discourse-cdn.com/v4/letter/k/ce73a5/32.png) [@Kulasangar\_Gowrisang](https://discuss.elastic.co/u/Kulasangar_Gowrisang)
#### Post date: [August 23, 2016, 11:26am UTC](https://discuss.elastic.co/t/how-to-format-yyyymmdd-to-yyyy-mm-dd-in-a-log-file/58666/4 "2016-08-23T11:26:30Z")

</div>

May I know how could I add my pattern **%{OWNTIMESTAMP}** as a new field?  
Tried adding this in both grok plus date filters but didn't work:

add\_field =\> { "logtimestamp" =\> "%{OWNTIMESTAMP}" }

---

<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 6, 2017, 4:42am UTC](https://discuss.elastic.co/t/how-to-format-yyyymmdd-to-yyyy-mm-dd-in-a-log-file/58666/5 "2017-07-06T04:42:04Z")

</div>


