# Get the date right now

**URL:** <https://discuss.elastic.co/t/get-the-date-right-now/113795>\
**Category:** Kibana\
**Created:** [January 2, 2018, 2:48pm UTC](https://discuss.elastic.co/t/get-the-date-right-now/113795 "2018-01-02T14:48:13Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![radi](https://avatars.discourse-cdn.com/v4/letter/r/4491bb/32.png) [@radi](https://discuss.elastic.co/u/radi)\
**Post date:** [January 2, 2018, 2:48pm UTC](https://discuss.elastic.co/t/get-the-date-right-now/113795/1 "2018-01-02T14:48:13Z")

</div>

hello,  
i have filed lastDate i whant to make script filed to calcul the diffrence of the value of lasteDate and the actual date  
there is way to get actual date in kibana ?

thank's

---

<div class="post-metadata">

**Author:** ![Joe\_Fleming](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joe_fleming/32/3561_2.png) [@Joe\_Fleming](https://discuss.elastic.co/u/Joe_Fleming)\
**Post date:** [January 2, 2018, 7:03pm UTC](https://discuss.elastic.co/t/get-the-date-right-now/113795/2 "2018-01-02T19:03:47Z")

</div>

By "actual date" I think you're talking about the date right now.

Scripted fields in Kibana simply use Elasticsearch's [Painless scripting language](https://www.elastic.co/guide/en/elasticsearch/painless/6.x/index.html). Unfortunately, that language can only be used to work with numbers, booleans, voids, and arrays. Since there is no way to operate on dates in the language, there is no way to calculate the difference between dates in scripted fields.

---

<div class="post-metadata">

**Author:** ![Joe\_Fleming](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joe_fleming/32/3561_2.png) [@Joe\_Fleming](https://discuss.elastic.co/u/Joe_Fleming)\
**Post date:** [January 2, 2018, 11:30pm UTC](https://discuss.elastic.co/t/get-the-date-right-now/113795/3 "2018-01-02T23:30:23Z")

</div>

Ah, Painless doesn't support dates, but the [expression syntax does](https://www.elastic.co/guide/en/elasticsearch/reference/6.1/modules-scripting-expression.html#_date_field_api). It's not clear to me how you'd get the current date to do the calculation with though.

---

<div class="post-metadata">

**Author:** ![radi](https://avatars.discourse-cdn.com/v4/letter/r/4491bb/32.png) [@radi](https://discuss.elastic.co/u/radi)\
**Post date:** [January 3, 2018, 1:47pm UTC](https://discuss.elastic.co/t/get-the-date-right-now/113795/4 "2018-01-03T13:47:08Z")

</div>

Thank you for your return. I used groovy to calculate the current date. and it's working good

---

<div class="post-metadata">

**Author:** ![Joe\_Fleming](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/joe_fleming/32/3561_2.png) [@Joe\_Fleming](https://discuss.elastic.co/u/Joe_Fleming)\
**Post date:** [January 3, 2018, 4:07pm UTC](https://discuss.elastic.co/t/get-the-date-right-now/113795/5 "2018-01-03T16:07:48Z")

</div>

Mind sharing how you got the current date in the Groovy script? I couldn't find an example that did that, and it would be useful to know what that looks like.

---

<div class="post-metadata">

**Author:** ![radi](https://avatars.discourse-cdn.com/v4/letter/r/4491bb/32.png) [@radi](https://discuss.elastic.co/u/radi)\
**Post date:** [January 3, 2018, 4:19pm UTC](https://discuss.elastic.co/t/get-the-date-right-now/113795/6 "2018-01-03T16:19:01Z")

</div>

> [@Joe\_Fleming](#):
>
> Mind sharing how you got the current date in the Groovy script? I couldn't find an example that did that, and it would be useful to know what that looks like.

```
this is my script_fields i called current data with "DateTime.now().getMillis()"

```

and i used it to compare with my session date

```
"script_fields" : {
      "Checks" : {
          "script" : {
         "lang": "groovy",
          "inline":
         "doc['sessionDate'].collect{ if (it!=0){ 
         if (((DateTime.now().getMillis()-it)/(1000*60*60*24))<60) 
         'check ok';else 'check no'; }else 'Never check'; }"
      }
    }
}

```

---

<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:** [January 31, 2018, 4:19pm UTC](https://discuss.elastic.co/t/get-the-date-right-now/113795/7 "2018-01-31T16:19:25Z")

</div>

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