# How do I convert the following date stamp into integers

**URL:** <https://discuss.elastic.co/t/how-do-i-convert-the-following-date-stamp-into-integers/187161>\
**Category:** Logstash\
**Created:** [June 24, 2019, 2:47pm UTC](https://discuss.elastic.co/t/how-do-i-convert-the-following-date-stamp-into-integers/187161 "2019-06-24T14:47:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![kganesan](https://avatars.discourse-cdn.com/v4/letter/k/c37758/32.png) [@kganesan](https://discuss.elastic.co/u/kganesan)\
**Post date:** [June 24, 2019, 2:47pm UTC](https://discuss.elastic.co/t/how-do-i-convert-the-following-date-stamp-into-integers/187161/1 "2019-06-24T14:47:01Z")

</div>

Hello.

I have the following date stamp info at the start of my log line and I need to convert them to integers.  
Log Line:  
2019-06-17 14:05:00.202  
Expected Output:  
Year: 2019  
Month: 06  
Date: 17  
Hours: 14  
Minutes: 05  
Sec: 00  
Millisec: 202

All the above fields should be in integer for my visualization purposes.

Is there any easy way to do it?  
Any help providing me with an example syntax 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:** [June 24, 2019, 3:13pm UTC](https://discuss.elastic.co/t/how-do-i-convert-the-following-date-stamp-into-integers/187161/2 "2019-06-24T15:13:03Z")

</div>

```
    mutate { add_field => { "someField" => "2019-06-17 14:05:00.202" } }
    date { match => ["someField", ISO8601] target => "[@metadata][ts]" }
    ruby {
        code => '
            epochMS = event.get("[@metadata][ts]").to_f * 1000
            dateTime = DateTime.strptime(epochMS.to_s, "%Q")
            event.set("Year", dateTime.year)
            event.set("Month", dateTime.month)
            event.set("Date", dateTime.day)
            event.set("Hours", dateTime.hour)
            event.set("Minutes", dateTime.minute)
            event.set("Sec", dateTime.second)
            event.set("Millisec", epochMS.to_i % 1000)
        '
    }
```

---

<div class="post-metadata">

**Author:** ![kganesan](https://avatars.discourse-cdn.com/v4/letter/k/c37758/32.png) [@kganesan](https://discuss.elastic.co/u/kganesan)\
**Post date:** [June 24, 2019, 6:16pm UTC](https://discuss.elastic.co/t/how-do-i-convert-the-following-date-stamp-into-integers/187161/3 "2019-06-24T18:16:21Z")

</div>

It has been converted to date time format but when I open the parsed logs in kibana I am getting the following errors.

Also the date hour min info are all wrong. only the captured field I named "loggedTime" seems right.

This is the filter I used:  
date  
{  
match =\> ["endTime", ISO8601 , "YYYY-MM-dd HH:mm:ss.ZZZ"]  
target =\> "loggedTime"  
}  
ruby {  
code =\> '  
epochMS = event.get("loggedTime").to\_f \* 1000  
dateTime = DateTime.strptime(epochMS.to\_s, "%Q")  
event.set("Year", dateTime.year)  
event.set("Month", dateTime.month)  
event.set("Date", dateTime.day)  
event.set("Hours", dateTime.hour)  
event.set("Minutes", dateTime.minute)  
event.set("Sec", dateTime.second)  
event.set("Millisec", epochMS.to\_i % 1000)  
'  
}

When I opened Kibana - the index I created I got th following error.  
"  
Discover: failed to parse date field [-61566890962977] with format [epoch\_millis]: [failed to parse date field [-61566890962977] with format [epoch\_millis]]

Less Info  
OK  
Error: Request to Elasticsearch failed: {"error":{"root\_cause":[{"type":"parse\_exception","reason":"failed to parse date field [-61566890962977] with format [epoch\_millis]: [failed to parse date field [-61566890962977] with format [epoch\_millis]]"}],"type":"search\_phase\_execution\_exception","reason":"all shards failed","phase":"query","grouped":true,"failed\_shards":[{"shard":0,"index":"datetimecon2","node":"UqVrXZn4TROzulIgqflqgA","reason":{"type":"parse\_exception","reason":"failed to parse date field [-61566890962977] with format [epoch\_millis]: [failed to parse date field [-61566890962977] with format [epoch\_millis]]","caused\_by":{"type":"illegal\_argument\_exception","reason":"failed to parse date field [-61566890962977] with format [epoch\_millis]","caused\_by":{"type":"date\_time\_parse\_exception","reason":"Failed to parse with all enclosed parsers"}}}}]},"status":400}  
at [http://localhost:5601/bundles/commons.bundle.js:3:1388766](http://localhost:5601/bundles/commons.bundle.js:3:1388766)  
at Function.Promise.try ([http://localhost:5601/bundles/commons.bundle.js:3:1065792](http://localhost:5601/bundles/commons.bundle.js:3:1065792))  
at [http://localhost:5601/bundles/commons.bundle.js:3:1065161](http://localhost:5601/bundles/commons.bundle.js:3:1065161)  
at Array.map ()  
at Function.Promise.map ([http://localhost:5601/bundles/commons.bundle.js:3:1065119](http://localhost:5601/bundles/commons.bundle.js:3:1065119))  
at callResponseHandlers ([http://localhost:5601/bundles/commons.bundle.js:3:1387778](http://localhost:5601/bundles/commons.bundle.js:3:1387778))  
at [http://localhost:5601/bundles/commons.bundle.js:3:1369738](http://localhost:5601/bundles/commons.bundle.js:3:1369738)  
at processQueue ([http://localhost:5601/built\_assets/dlls/vendors.bundle.dll.js:427:199687](http://localhost:5601/built_assets/dlls/vendors.bundle.dll.js:427:199687))  
at [http://localhost:5601/built\_assets/dlls/vendors.bundle.dll.js:427:200650](http://localhost:5601/built_assets/dlls/vendors.bundle.dll.js:427:200650)  
at Scope.$digest ([http://localhost:5601/built\_assets/dlls/vendors.bundle.dll.js:427:210412](http://localhost:5601/built_assets/dlls/vendors.bundle.dll.js:427:210412))"

 ![kibana%20snapshot](https://us1.discourse-cdn.com/elastic/original/3X/4/f/4f2d244da91bbad0ce0d18d5aa6957204a165fc9.png)

---

<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:** [June 24, 2019, 7:07pm UTC](https://discuss.elastic.co/t/how-do-i-convert-the-following-date-stamp-into-integers/187161/4 "2019-06-24T19:07:52Z")

</div>

My guess is that your [index mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-get-mapping.html) maps Date as a date. If you rename that field to dayOfMonth do the errors go away?

---

<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:** [July 22, 2019, 7:07pm UTC](https://discuss.elastic.co/t/how-do-i-convert-the-following-date-stamp-into-integers/187161/5 "2019-07-22T19:07:52Z")

</div>

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