# Get current time

**URL:** https://discuss.elastic.co/t/get-current-time/181609
**Category:** Logstash
**Created:** [May 17, 2019, 2:14pm UTC](https://discuss.elastic.co/t/get-current-time/181609 "2019-05-17T14:14:16Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Android\_Games](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/android_games/32/45618_2.png) [@Android\_Games](https://discuss.elastic.co/u/Android_Games)
#### Post date: [May 17, 2019, 2:14pm UTC](https://discuss.elastic.co/t/get-current-time/181609/1 "2019-05-17T14:14:17Z")

</div>

i would like to get the current timestamp from logstash, currently i'm using the following code to get the current time.

```
        input { 
stdin { codec => json }
# Supports "cron", "every", "at" and "in" schedules by rufus scheduler
schedule => { cron => "* * * * * UTC"}

```

}  
filter {  
ruby {  
code =\> "event.set('updated\_date', event.get('@timestamp'))"  
}  
}  
output  
{  
elasticsearch  
{  
index =\> "test"

}  
}

---

<div class="post-metadata">

### Author: ![pastechecker](https://avatars.discourse-cdn.com/v4/letter/p/0ea827/32.png) [@pastechecker](https://discuss.elastic.co/u/pastechecker)
#### Post date: [May 17, 2019, 2:23pm UTC](https://discuss.elastic.co/t/get-current-time/181609/2 "2019-05-17T14:23:07Z")

</div>

By current timestamp you mean the event processing time that is named @timestamp?

Your code does now the following:

{  
"updated\_date" =\> 2019-05-17T14:23:37.396Z,  
"@version" =\> "1",  
"message" =\> "helloworld",  
"@timestamp" =\> 2019-05-17T14:23:37.396Z,  
"host" =\> "testnode"  
}

You can also do it:

```
filter {
ruby {
code => "event.set('updated_date', event.get('@timestamp'))"
}
mutate {
    add_field => { "mutate_time" => "%{@timestamp}" }
}
}

```

{  
"@version" =\> "1",  
"@timestamp" =\> 2019-05-17T14:25:32.110Z,  
"mutate\_time" =\> "2019-05-17T14:25:32.110Z",  
"updated\_date" =\> 2019-05-17T14:25:32.110Z,  
"host" =\> "testnode",  
"message" =\> "mutate\_time"  
}

---

<div class="post-metadata">

### Author: ![A\_B](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/a_b/32/17104_2.png) [@A\_B](https://discuss.elastic.co/u/A_B)
#### Post date: [May 17, 2019, 3:10pm UTC](https://discuss.elastic.co/t/get-current-time/181609/3 "2019-05-17T15:10:26Z")

</div>

One possible way would be to create a field at the start of the `filter` section like this (I do something similar)

```
  alter {
    add_field => {
      "[@metadata][now]" => "%{+YYYY.MM.dd.ss:SSS}"
    }
  }

```

Format it however you want. This can be added to any log message or used as the source to overwrite other fields...

---

<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: [June 14, 2019, 3:10pm UTC](https://discuss.elastic.co/t/get-current-time/181609/4 "2019-06-14T15:10:38Z")

</div>

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