# Create a new field (customdate) like yyyy-mm(2020-08) format from eventstamp(1597739955692) type Epoch

**URL:** <https://discuss.elastic.co/t/create-a-new-field-customdate-like-yyyy-mm-2020-08-format-from-eventstamp-1597739955692-type-epoch/246516>\
**Category:** Logstash\
**Created:** [August 26, 2020, 9:41pm UTC](https://discuss.elastic.co/t/create-a-new-field-customdate-like-yyyy-mm-2020-08-format-from-eventstamp-1597739955692-type-epoch/246516 "2020-08-26T21:41:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wishnu2016](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wishnu2016/32/46349_2.png) [@wishnu2016](https://discuss.elastic.co/u/wishnu2016)\
**Post date:** [August 26, 2020, 9:41pm UTC](https://discuss.elastic.co/t/create-a-new-field-customdate-like-yyyy-mm-2020-08-format-from-eventstamp-1597739955692-type-epoch/246516/1 "2020-08-26T21:41:21Z")

</div>

I want to create a new field with a year-month format (yyyy-mm, 2020-08) from the eventstamp field which I am receiving in Epoch format. I am new to logstash, I was able to add a new field but I don't know how to covert the epoch to custom date format.

```auto
 add_field => {
            "customdate" => "%{timestamp}"
        }

```

Appreciate your help in advance. Thank you.

---

<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:** [August 26, 2020, 10:53pm UTC](https://discuss.elastic.co/t/create-a-new-field-customdate-like-yyyy-mm-2020-08-format-from-eventstamp-1597739955692-type-epoch/246516/2 "2020-08-26T22:53:26Z")

</div>

I would do that using

```
    date { match => ["eventstamp", "UNIX_MS"] target => "[@metadata][timestamp]" }
    ruby { code => ' event.set("customdate", Time.at(event.get("[@metadata][timestamp]").to_f).strftime("%Y/%m")) ' }
```

---

<div class="post-metadata">

**Author:** ![wishnu2016](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/wishnu2016/32/46349_2.png) [@wishnu2016](https://discuss.elastic.co/u/wishnu2016)\
**Post date:** [August 27, 2020, 3:17pm UTC](https://discuss.elastic.co/t/create-a-new-field-customdate-like-yyyy-mm-2020-08-format-from-eventstamp-1597739955692-type-epoch/246516/3 "2020-08-27T15:17:23Z")

</div>

@Badger Thanks, it worked and I was able to convert the date format as well.

---

<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:** [September 24, 2020, 3:17pm UTC](https://discuss.elastic.co/t/create-a-new-field-customdate-like-yyyy-mm-2020-08-format-from-eventstamp-1597739955692-type-epoch/246516/4 "2020-09-24T15:17:28Z")

</div>

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