# Grok DATA as MONTH-NUMBER

**URL:** https://discuss.elastic.co/t/grok-data-as-month-number/219243
**Category:** Logstash
**Created:** [February 13, 2020, 3:42pm UTC](https://discuss.elastic.co/t/grok-data-as-month-number/219243 "2020-02-13T15:42:47Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![ldistria79](https://avatars.discourse-cdn.com/v4/letter/l/f04885/32.png) [@ldistria79](https://discuss.elastic.co/u/ldistria79)
#### Post date: [February 13, 2020, 3:42pm UTC](https://discuss.elastic.co/t/grok-data-as-month-number/219243/1 "2020-02-13T15:42:47Z")

</div>

Hi All,  
i have two date types:  
"2020-02-12 09:37:19,334" and "2020Feb07-10:42:22", I'd like to import a unique format into kibana.

Currently I worked on the second one, using grok I was able to read "2020Feb07-10:42:22" with:  
%{YEAR}%{DATA}%{MONTHDAY}-%{TIME}

The problem is that I'd like to read "%{DATA}" as "%{MONTH}, but if I use MONTH grok doesn't see Feb as the second Month.  
Please help.

---

<div class="post-metadata">

### Author: ![Fabio-sama](https://avatars.discourse-cdn.com/v4/letter/f/b9e5f3/32.png) [@Fabio-sama](https://discuss.elastic.co/u/Fabio-sama)
#### Post date: [February 16, 2020, 10:45am UTC](https://discuss.elastic.co/t/grok-data-as-month-number/219243/2 "2020-02-16T10:45:35Z")

</div>

Hi Luigi,

I don't know if you can make a mapping `month_in_letters -> month_as_num` directly in the Grok filter. Though, if you want to make the second date type similar to the first one, you can always use a ruby filter to assemble it and then remove the useless fields with a `remove_field` filter. Supposing your grok is `%{YEAR:year}%{DATA:month}%{MONTHDAY:day}-%{TIME:time}`, then you can make a filter similar to the following:

```
ruby {
  code => "
    year = event.get('year')
    month = event.get('month')[0..2].capitalize 
    day = event.get('day')
    time = event.get('time')
    month_to_num = { 'Jan': '01', 'Feb':'02', 'Mar':'03', 'Apr':'04', 'May':'05', 'Jun':'06', 'Jul':'07', 'Aug':'08', 'Sep': '09', 'Oct':'10', 'Nov':'11', 'Dec':'12' }    
    
    unless [year, month, date, time].include? nil
      new_date = year + '-' + month_to_num[month] + '-' + day + ' ' + time
      event.set('new_timestamp', new_date)
    end
  "

  mutate {
    remove_field => ["year", "month", "day", "time"]
  }
}

```

It's not the most elegant way but it should fit your needs 🙂

---

<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 15, 2020, 10:45am UTC](https://discuss.elastic.co/t/grok-data-as-month-number/219243/3 "2020-03-15T10:45:36Z")

</div>

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