# How to convert date to a single type in a Painless script?

**URL:** <https://discuss.elastic.co/t/how-to-convert-date-to-a-single-type-in-a-painless-script/179948>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [May 7, 2019, 11:27am UTC](https://discuss.elastic.co/t/how-to-convert-date-to-a-single-type-in-a-painless-script/179948 "2019-05-07T11:27:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hohol](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hohol/32/37372_2.png) [@Hohol](https://discuss.elastic.co/u/Hohol)\
**Post date:** [May 7, 2019, 11:27am UTC](https://discuss.elastic.co/t/how-to-convert-date-to-a-single-type-in-a-painless-script/179948/1 "2019-05-07T11:27:17Z")

</div>

It's required for [https://github.com/elastic/kibana/pull/25379](https://github.com/elastic/kibana/pull/25379)  
I need to access a date field in a Painless script, but I don't know what its type is.  
I know there are at least two possible types - `Long` (epoch milliseconds) and `JodaCompatibleZonedDateTime`. Probably there are more.  
So I need some way to convert date from one of possible types to a single type.  
The method `org.elasticsearch.xpack.core.watcher.support.WatcherDateTimeUtils#convertToDate` does similar thing, but it's not available inside a Painless script.

If there is no such functionality, I can try to add it.

---

<div class="post-metadata">

**Author:** ![Jack\_Conradson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jack_conradson/32/47236_2.png) [@Jack\_Conradson](https://discuss.elastic.co/u/Jack_Conradson)\
**Post date:** [May 10, 2019, 2:42pm UTC](https://discuss.elastic.co/t/how-to-convert-date-to-a-single-type-in-a-painless-script/179948/2 "2019-05-10T14:42:39Z")

</div>

I believe the concerns here have been addressed in ([https://github.com/elastic/elasticsearch/issues/41936](https://github.com/elastic/elasticsearch/issues/41936)).

---

<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 7, 2019, 2:42pm UTC](https://discuss.elastic.co/t/how-to-convert-date-to-a-single-type-in-a-painless-script/179948/3 "2019-06-07T14:42:53Z")

</div>

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