# Help in Parsing date from timestamp using painless

**URL:** <https://discuss.elastic.co/t/help-in-parsing-date-from-timestamp-using-painless/157233>\
**Category:** Kibana\
**Created:** [November 18, 2018, 4:00pm UTC](https://discuss.elastic.co/t/help-in-parsing-date-from-timestamp-using-painless/157233 "2018-11-18T16:00:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dhana](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@Dhana](https://discuss.elastic.co/u/Dhana)\
**Post date:** [November 18, 2018, 4:00pm UTC](https://discuss.elastic.co/t/help-in-parsing-date-from-timestamp-using-painless/157233/1 "2018-11-18T16:00:27Z")

</div>

Hi, Could any one please help me getting the date from the timestamp using painless in the scripted field and group the data-set based on date,

doc['timestamp'].date.monthOfYear + '/' + doc['timestamp'].date.dayOfMonth + '/' + doc['timestamp'].date.year

I am trying to the get the count based on the date as below.

| | 11/17/2018 | 11/16/2018 | 11/15/2018 |
| --- | --- | --- | --- |
| Row1 | 10 | 25 | 333 |
| Row2 | 21 | 44 | 35 |
| Row3 | 22 | 11 | 24 |

Thanks.

---

<div class="post-metadata">

**Author:** ![thomasneirynck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomasneirynck/32/23313_2.png) [@thomasneirynck](https://discuss.elastic.co/u/thomasneirynck)\
**Post date:** [November 19, 2018, 5:09pm UTC](https://discuss.elastic.co/t/help-in-parsing-date-from-timestamp-using-painless/157233/2 "2018-11-19T17:09:15Z")

</div>

@Dhana ,

that painless script looks correct, or am I missing something?

you can create a scripted-field with that script. [https://www.elastic.co/guide/en/kibana/current/scripted-fields.html](https://www.elastic.co/guide/en/kibana/current/scripted-fields.html). You'll create a new string-field on the fly.

Then, you'll be able to do a terms-aggregation on that field and do a count by date.

---

<div class="post-metadata">

**Author:** ![Dhana](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@Dhana](https://discuss.elastic.co/u/Dhana)\
**Post date:** [November 19, 2018, 6:11pm UTC](https://discuss.elastic.co/t/help-in-parsing-date-from-timestamp-using-painless/157233/3 "2018-11-19T18:11:17Z")

</div>

Hi,

Thanks for confirming. So I can create a field name " test\_scripted\_field1" as string and use that for count.

Could you please verify the below configuration parameters and confirm.

Name - test\_scripted\_field1  
Language - painless  
Type - String  
Transform - none  
Popularity - 0  
Script  
doc['timestamp'].date.monthOfYear + '/' + doc['timestamp'].date.dayOfMonth + '/' + doc['timestamp'].date.year

 ![Kibana_configuration](https://us1.discourse-cdn.com/elastic/original/3X/3/3/331d09caedb2817a1527c17ecd353c98fabacbf9.jpeg)

Thanks,  
Dhana

---

<div class="post-metadata">

**Author:** ![thomasneirynck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomasneirynck/32/23313_2.png) [@thomasneirynck](https://discuss.elastic.co/u/thomasneirynck)\
**Post date:** [November 19, 2018, 7:39pm UTC](https://discuss.elastic.co/t/help-in-parsing-date-from-timestamp-using-painless/157233/4 "2018-11-19T19:39:25Z")

</div>

yes that looks good I think.

you can verify if this works in the "Discover" application of Kibana. Select your index-pattern there and look for that new `test_scripted_field1` on the left-side. Select it, and see what the results look like.

---

<div class="post-metadata">

**Author:** ![Dhana](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@Dhana](https://discuss.elastic.co/u/Dhana)\
**Post date:** [November 19, 2018, 10:29pm UTC](https://discuss.elastic.co/t/help-in-parsing-date-from-timestamp-using-painless/157233/5 "2018-11-19T22:29:38Z")

</div>

Hi, I tried the steps provided but I was getting the error on the discover page, and I was not getting any result on the logs. So I have to delete the created field and the log started loading on the discover screen on discover.

Could you please help me to resolve the issue.

Thanks.

---

<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:** [December 17, 2018, 10:29pm UTC](https://discuss.elastic.co/t/help-in-parsing-date-from-timestamp-using-painless/157233/6 "2018-12-17T22:29:46Z")

</div>

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