# Getting Current date in Painless

**URL:** <https://discuss.elastic.co/t/getting-current-date-in-painless/225227>\
**Category:** Elasticsearch\
**Created:** [March 26, 2020, 3:33pm UTC](https://discuss.elastic.co/t/getting-current-date-in-painless/225227 "2020-03-26T15:33:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Be1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/be1/32/63657_2.png) [@Be1](https://discuss.elastic.co/u/Be1)\
**Post date:** [March 26, 2020, 3:33pm UTC](https://discuss.elastic.co/t/getting-current-date-in-painless/225227/1 "2020-03-26T15:33:57Z")

</div>

Hello,  
I want to get the difference of current today and another date field as 'age' field.(new field)  
So i was trying to add a dynamic script field in elastic search.Below is the query i used

```auto
curl -XPOST 'localhost:9200/test8/_search' -H 'Content-Type: application/json' -d '{
 "query": {
{

  "query": {
    "match_all": {}
  },
 "_source" : [],
  "script_fields": {
    "age1": {
      "script": "(Date().getTime()- doc['Request Date'].value)/(24*60*60*1000)"
    }
  }
}
}

```

But i get this error "Variable [DateTime] is not defined.  
Seems like Date().getTime() cannot fetch the current date in painless  
Could anyone let me know what is the syntax to get current date in painless.  
I am using elastic search 7.6.0 and kibana 7.6.0  
Thanks in advance

---

<div class="post-metadata">

**Author:** ![Opster\_Community1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/opster_community1/32/59062_2.png) [@Opster\_Community1](https://discuss.elastic.co/u/Opster_Community1)\
**Post date:** [March 27, 2020, 6:05am UTC](https://discuss.elastic.co/t/getting-current-date-in-painless/225227/2 "2020-03-27T06:05:09Z")

</div>

Please wrap your code with ``` so that it is readable.

---

<div class="post-metadata">

**Author:** ![Opster\_Community1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/opster_community1/32/59062_2.png) [@Opster\_Community1](https://discuss.elastic.co/u/Opster_Community1)\
**Post date:** [March 30, 2020, 2:56am UTC](https://discuss.elastic.co/t/getting-current-date-in-painless/225227/3 "2020-03-30T02:56:54Z")

</div>

Add index mapping and sample document so that we can replicate. Also add the expected result.

---

<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:** [April 27, 2020, 2:57am UTC](https://discuss.elastic.co/t/getting-current-date-in-painless/225227/4 "2020-04-27T02:57:05Z")

</div>

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