# Current Time

**URL:** <https://discuss.elastic.co/t/current-time/107863>\
**Category:** Elasticsearch\
**Created:** [November 16, 2017, 5:42am UTC](https://discuss.elastic.co/t/current-time/107863 "2017-11-16T05:42:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![hamrio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hamrio/32/23499_2.png) [@hamrio](https://discuss.elastic.co/u/hamrio)\
**Post date:** [November 16, 2017, 5:42am UTC](https://discuss.elastic.co/t/current-time/107863/1 "2017-11-16T05:42:31Z")

</div>

Hi,

Is there someway to get current time at script fields? Usually for getting in range I can use now, but for scripted query it returns as string. I've searched some topic and it said, it must be send by params. Is there any guide for doing this?

Thank you

---

<div class="post-metadata">

**Author:** ![nugusbayevkk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nugusbayevkk/32/126683_2.png) [@nugusbayevkk](https://discuss.elastic.co/u/nugusbayevkk)\
**Post date:** [November 16, 2017, 5:59am UTC](https://discuss.elastic.co/t/current-time/107863/2 "2017-11-16T05:59:24Z")

</div>

hi,  
i understood that under script fields you mean bash scripts?  
if that, so you can use in range query values like:

> "'`date '+%Y-%m-%dT%H:%M:%S%Z'`'"

, that return current time.  
here example with range from 4 hour from now to now

> curl localhost:9200/sslogger\_index/events/\_search -d '{"query": {"range": {"event\_date": {"gte":"'`date '+%Y-%m-%dT%H:%M:%S%Z' -d '4 hour ago'`'", "lt":"'`date '+%Y-%m-%dT%H:%M:%S%Z'`'"}}}}'

---

<div class="post-metadata">

**Author:** ![hamrio](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hamrio/32/23499_2.png) [@hamrio](https://discuss.elastic.co/u/hamrio)\
**Post date:** [November 16, 2017, 6:57am UTC](https://discuss.elastic.co/t/current-time/107863/3 "2017-11-16T06:57:27Z")

</div>

Hi,

No, I mean the painless one. as we used in scripted field for elastic search. I use kibana console for query and search the elastic search.

Thank you

---

<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 14, 2017, 6:57am UTC](https://discuss.elastic.co/t/current-time/107863/4 "2017-12-14T06:57:29Z")

</div>

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