# Painless get date today

**URL:** <https://discuss.elastic.co/t/painless-get-date-today/81264>\
**Category:** Elasticsearch\
**Created:** [April 5, 2017, 7:50am UTC](https://discuss.elastic.co/t/painless-get-date-today/81264 "2017-04-05T07:50:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bertvervaele](https://avatars.discourse-cdn.com/v4/letter/b/8e7dd6/32.png) [@bertvervaele](https://discuss.elastic.co/u/bertvervaele)\
**Post date:** [April 5, 2017, 7:50am UTC](https://discuss.elastic.co/t/painless-get-date-today/81264/1 "2017-04-05T07:50:20Z")

</div>

Since there is not a lot of information around painless yet I hope there is someone here with experience in it.  
I want to filter all messages that happend on the same day of the week. So like today I want all messages that happend on a wednesday.  
So is there a way to get todays Date?  
This is my script but today.date.dayOfWeek should get changed.  
(I would like to do the same with the hour)

```
GET _search
    {
      "query": {
        "bool": {
          "filter": {
            "script": {
              "script": "doc['@timestamp'].date.dayOfWeek == today.date.dayOfWeek"
            }
          }
        }
      }
    }
```

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [April 5, 2017, 1:39pm UTC](https://discuss.elastic.co/t/painless-get-date-today/81264/2 "2017-04-05T13:39:45Z")

</div>

Painless intentionally doesn't have any access to `now` style variables so they can be better cached. The current recommendation is for you to send `now` style variables in over scripts `params`.

BTW, you should know that this query isn't able to take advantage of the index at all. It'll have to load the `@timestamp` field for every document and compare it. This much much slower than extracting the day of the week on ingest and adding it to the document.

---

<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:** [May 3, 2017, 1:39pm UTC](https://discuss.elastic.co/t/painless-get-date-today/81264/3 "2017-05-03T13:39:57Z")

</div>

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