# How to convert parsed date into long (epoch time)

**URL:** <https://discuss.elastic.co/t/how-to-convert-parsed-date-into-long-epoch-time/167202>\
**Category:** Logstash\
**Created:** [February 6, 2019, 1:29am UTC](https://discuss.elastic.co/t/how-to-convert-parsed-date-into-long-epoch-time/167202 "2019-02-06T01:29:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shimpi](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@shimpi](https://discuss.elastic.co/u/shimpi)\
**Post date:** [February 6, 2019, 1:29am UTC](https://discuss.elastic.co/t/how-to-convert-parsed-date-into-long-epoch-time/167202/1 "2019-02-06T01:29:03Z")

</div>

I'm parsing tomcat log

> 2019-01-31 23:25:27,421 INFO SNOW FAA31C764BD69D829C09715487B1E923 [Thread-16]

using:

> grok {  
> match =\> { "message" =\> "%{TIMESTAMP\_ISO8601:date} %{LOGLEVEL:loglevel} %{WORD:GW} %{WORD:GUID}" }  
> }

It creates a date field: "date" =\> "2019-01-31 23:25:27,421",

Please help me convert this date into a long (epoc time)

Thanks in advance!

---

<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:** [February 6, 2019, 1:43am UTC](https://discuss.elastic.co/t/how-to-convert-parsed-date-into-long-epoch-time/167202/2 "2019-02-06T01:43:42Z")

</div>

The format is

```
    date { match => ["date" , "YYYY-MM-dd HH:mm:ss,SSS"] }

```

You cannot use @timestamp as the target for anything other than a LogStash::TimeStamp.

---

<div class="post-metadata">

**Author:** ![shimpi](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@shimpi](https://discuss.elastic.co/u/shimpi)\
**Post date:** [February 6, 2019, 2:11am UTC](https://discuss.elastic.co/t/how-to-convert-parsed-date-into-long-epoch-time/167202/3 "2019-02-06T02:11:24Z")

</div>

Thanks for the response @Badger. I was searching around, but at end could not figure out where's my long (epoc) time?

What I would really want to do is, keep the date field intact and copy the corresponding long in new field, which I could use later.

Thanks in advance!

---

<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:** [February 6, 2019, 1:22pm UTC](https://discuss.elastic.co/t/how-to-convert-parsed-date-into-long-epoch-time/167202/4 "2019-02-06T13:22:12Z")

</div>

> [@shimpi](#):
>
> What I would really want to do is, keep the date field intact and copy the corresponding long in new field, which I could use later.

If you want epoch in millis then use this (remove to\_s if you want a long rather than a string)

```
ruby { code => "event.set('epoch', ((event.get('@timestamp').to_f*1000).to_i).to_s)" }

```

In seconds

```
ruby { code => "event.set('epoch', event.get('@timestamp').to_i)" }

```

---

<div class="post-metadata">

**Author:** ![shimpi](https://avatars.discourse-cdn.com/v4/letter/s/7ba0ec/32.png) [@shimpi](https://discuss.elastic.co/u/shimpi)\
**Post date:** [February 6, 2019, 6:40pm UTC](https://discuss.elastic.co/t/how-to-convert-parsed-date-into-long-epoch-time/167202/5 "2019-02-06T18:40:45Z")

</div>

Thanks @Badger again for helping me!

---

<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 6, 2019, 6:40pm UTC](https://discuss.elastic.co/t/how-to-convert-parsed-date-into-long-epoch-time/167202/6 "2019-03-06T18:40:45Z")

</div>

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