# Generate date time string automatically

**URL:** https://discuss.elastic.co/t/generate-date-time-string-automatically/355853
**Category:** Kibana
**Created:** [March 20, 2024, 10:05pm UTC](https://discuss.elastic.co/t/generate-date-time-string-automatically/355853 "2024-03-20T22:05:33Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![elichai](https://avatars.discourse-cdn.com/v4/letter/e/7feea3/32.png) [@elichai](https://discuss.elastic.co/u/elichai)
#### Post date: [March 20, 2024, 10:05pm UTC](https://discuss.elastic.co/t/generate-date-time-string-automatically/355853/1 "2024-03-20T22:05:33Z")

</div>

Hi,  
I am using Kibana and DSL query. I am searching a range of dates which should be set when I am running the query. For example - setting one date field with the current date and another 6 days earlier than the current date, all in the same JSON. In the following snippet the dates should be according the execution date and not "hard coded".

```auto
{
    "range": {
        "customs_statuses.date_time": {
            "gte": "2024-03-14",
            "lte": "2024-03-20"
        }
    }
}

```

Thanks

---

<div class="post-metadata">

### Author: ![Priscilla\_Parodi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/priscilla_parodi/32/43047_2.png) [@Priscilla\_Parodi](https://discuss.elastic.co/u/Priscilla_Parodi)
#### Post date: [March 20, 2024, 10:38pm UTC](https://discuss.elastic.co/t/generate-date-time-string-automatically/355853/2 "2024-03-20T22:38:26Z")

</div>

Hello @elichai, welcome to the community!

You can use [date math](https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#date-math), if I understood correctly, something like this:

```auto
{
  "range": {
    "customs_statuses.date_time": {
      "gte": "now-6d/d",
      "lte": "now/d"
    }
  }
}

```

---

<div class="post-metadata">

### Author: ![elichai](https://avatars.discourse-cdn.com/v4/letter/e/7feea3/32.png) [@elichai](https://discuss.elastic.co/u/elichai)
#### Post date: [March 21, 2024, 4:16am UTC](https://discuss.elastic.co/t/generate-date-time-string-automatically/355853/3 "2024-03-21T04:16:20Z")

</div>

> [@Priscilla\_Parodi](#):
>
> `"now-6d/d"`

Great. Thanks for the prompt answer.

---

<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 18, 2024, 4:17am UTC](https://discuss.elastic.co/t/generate-date-time-string-automatically/355853/4 "2024-04-18T04:17:16Z")

</div>

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