# I want to add "yyyy-MM-dd" for Time field

**URL:** <https://discuss.elastic.co/t/i-want-to-add-yyyy-mm-dd-for-time-field/269079>\
**Category:** Logstash\
**Created:** [April 2, 2021, 1:22am UTC](https://discuss.elastic.co/t/i-want-to-add-yyyy-mm-dd-for-time-field/269079 "2021-04-02T01:22:41Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![BlackCat](https://avatars.discourse-cdn.com/v4/letter/b/c37758/32.png) [@BlackCat](https://discuss.elastic.co/u/BlackCat)\
**Post date:** [April 2, 2021, 1:22am UTC](https://discuss.elastic.co/t/i-want-to-add-yyyy-mm-dd-for-time-field/269079/1 "2021-04-02T01:22:41Z")

</div>

I want to use "yyyy-MM-dd" from current time.  
Please teach me how to do it.

Raw log.

```auto
 9:36:02 (tableau) (@tableau-SLOG@) === Memory Usage Info ===

```

I use below grok.

```auto
grok {
 match => { "message" => "%{TIME:Time} %{GREEDYDATA:Message}" }
}

```

---

<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:** [April 2, 2021, 1:52am UTC](https://discuss.elastic.co/t/i-want-to-add-yyyy-mm-dd-for-time-field/269079/2 "2021-04-02T01:52:50Z")

</div>

Are you saying you have a log file format that only includes the time, so you want to add the current date to it when building [@timestamp] ?

---

<div class="post-metadata">

**Author:** ![BlackCat](https://avatars.discourse-cdn.com/v4/letter/b/c37758/32.png) [@BlackCat](https://discuss.elastic.co/u/BlackCat)\
**Post date:** [April 2, 2021, 2:26am UTC](https://discuss.elastic.co/t/i-want-to-add-yyyy-mm-dd-for-time-field/269079/3 "2021-04-02T02:26:45Z")

</div>

Raw log have only time of "HH:mm:ss".  
I want to add yyyy-MM-dd the %{TIME:Time} field.

---

<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:** [April 2, 2021, 4:12pm UTC](https://discuss.elastic.co/t/i-want-to-add-yyyy-mm-dd-for-time-field/269079/4 "2021-04-02T16:12:39Z")

</div>

You could use

```
ruby { code => 'event.set("[@metadata][date]", Time.now.strftime("%Y-%m-%d")' }
mutate { add_field => { "[@metadata][timestamp]" => "%{[@metadata][date]} %{time}" } }
date { match => ["[@metadata][timestamp]", "YYYY-MM-dd HH:mm:ss" ] }

```

However, if an event arrives on 2021/04/03 00:00:01 which has the time set to 23:59:59 this will result in @timestamp being set to 2021/04/03 23:59:59, which is obviously wrong. You can write some logic to improve the guessed date, but that is not easy. There are open issues around guessing dates in the date filter [here](https://github.com/logstash-plugins/logstash-filter-date/issues/51), [here](https://github.com/logstash-plugins/logstash-filter-date/issues/100), and [here](https://github.com/logstash-plugins/logstash-filter-date/issues/137). They might give you some ideas around pitfalls the logic will need to avoid.

---

<div class="post-metadata">

**Author:** ![BlackCat](https://avatars.discourse-cdn.com/v4/letter/b/c37758/32.png) [@BlackCat](https://discuss.elastic.co/u/BlackCat)\
**Post date:** [April 7, 2021, 6:25am UTC](https://discuss.elastic.co/t/i-want-to-add-yyyy-mm-dd-for-time-field/269079/5 "2021-04-07T06:25:53Z")

</div>

Thanks reply, Badger.

But, I decided use @timestamp due to I want raw time.

```auto
grok {
 match => { "message" => "%{GREEDYDATA:Message}" }
}
mutate {
   copy => { "@timestamp" => "Time" }
}

```

---

<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:** [May 5, 2021, 6:25am UTC](https://discuss.elastic.co/t/i-want-to-add-yyyy-mm-dd-for-time-field/269079/6 "2021-05-05T06:25:59Z")

</div>

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