# GROK Filter - Extract Year and Month

**URL:** https://discuss.elastic.co/t/grok-filter-extract-year-and-month/291470
**Category:** Logstash
**Created:** [December 10, 2021, 9:08pm UTC](https://discuss.elastic.co/t/grok-filter-extract-year-and-month/291470 "2021-12-10T21:08:34Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![JeremyP](https://avatars.discourse-cdn.com/v4/letter/j/43a26b/32.png) [@JeremyP](https://discuss.elastic.co/u/JeremyP)
#### Post date: [December 10, 2021, 9:08pm UTC](https://discuss.elastic.co/t/grok-filter-extract-year-and-month/291470/1 "2021-12-10T21:08:34Z")

</div>

Hi.... I'm looking for some help on creating a new field based on a grok pattern.

Here is the field in question:

`"last_assessed_for_vulnerabilities": "2021-12-10T07:05:41.154Z"`

I'm looking to create the following field using the year and month date...

`report_period : 2021-12`

I'm close, but I can't seem to get GROK to process the month properly. Any help is appreciated!

---

<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: [December 10, 2021, 10:01pm UTC](https://discuss.elastic.co/t/grok-filter-extract-year-and-month/291470/2 "2021-12-10T22:01:45Z")

</div>

How about

```
grok {
    pattern_definition => { "MYDATE" => "%{YEAR}-%{MONTHNUM}" }
    match => { "last_assessed_for_vulnerabilities" => "^%{MYDATE:someFeild}" }
}
```

---

<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: [January 7, 2022, 10:02pm UTC](https://discuss.elastic.co/t/grok-filter-extract-year-and-month/291470/3 "2022-01-07T22:02:13Z")

</div>

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