# Add +1 day to Datefield Kibana scripted fields

**URL:** <https://discuss.elastic.co/t/add-1-day-to-datefield-kibana-scripted-fields/258595>\
**Category:** Kibana\
**Tags:** painless\
**Created:** [December 14, 2020, 3:17pm UTC](https://discuss.elastic.co/t/add-1-day-to-datefield-kibana-scripted-fields/258595 "2020-12-14T15:17:00Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Datakids](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/datakids/32/39622_2.png) [@Datakids](https://discuss.elastic.co/u/Datakids)\
**Post date:** [December 14, 2020, 3:17pm UTC](https://discuss.elastic.co/t/add-1-day-to-datefield-kibana-scripted-fields/258595/1 "2020-12-14T15:17:01Z")

</div>

Hi there,  
I wonder how to add a Day to existing Date field.

For example:  
 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/2/8241d285d962bba72217f2adbb2620b4dbd532cb.png)

Left Date is Original and I need on right hand the origin date + 1 Day

Type: Date  
Format: Date

I tried:  
doc['Datum'].value + ("1d")  
doc['Datum'].value + ("24:00:00") etc

but this way not work.

How can I do that in scripted fields?

Thanks in advance for your help

Regards

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [December 14, 2020, 3:34pm UTC](https://discuss.elastic.co/t/add-1-day-to-datefield-kibana-scripted-fields/258595/2 "2020-12-14T15:34:50Z")

</div>

I did this in the Painless Lab but should still work.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/6/3/6360327e266c7fb7ebb0b62469a49cb8e3b352cb.png)

```auto
String datetime = '1983-10-13T22:15:30Z';
ZonedDateTime zdt = ZonedDateTime.parse(datetime); 

ZonedDateTime updatedZdt = zdt.plusDays(1);

return updatedZdt;

```

References:  
[Using Datetime in Painless](https://www.elastic.co/guide/en/elasticsearch/painless/7.10/painless-datetime.html#painless-datetime)

---

<div class="post-metadata">

**Author:** ![Datakids](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/datakids/32/39622_2.png) [@Datakids](https://discuss.elastic.co/u/Datakids)\
**Post date:** [December 14, 2020, 3:59pm UTC](https://discuss.elastic.co/t/add-1-day-to-datefield-kibana-scripted-fields/258595/3 "2020-12-14T15:59:43Z")

</div>

Hi Aaron,  
thanks for your prompt answer

yes your snipet for this particular date string works, even in kibana 7.3.0  
but how to access the Datum field itself?

I add a scripted field "Datum+1" (Type String, Format String): from doc['Datum'].value  
And add this new field to your snipet but wont work (even if i use the date field)

String datetime = doc['Datum+1'].value;  
ZonedDateTime zdt = ZonedDateTime.parse(datetime);  
ZonedDateTime updatedZdt = zdt.plusDays(1);  
return updatedZdt;

Any Idea

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [December 14, 2020, 4:18pm UTC](https://discuss.elastic.co/t/add-1-day-to-datefield-kibana-scripted-fields/258595/4 "2020-12-14T16:18:04Z")

</div>

In scripted fields I just test this on 7.10. Let me know if it doesn't work in your version.

Just replace `@timestamp` with your field name which I think is `Datum`.

```auto
ZonedDateTime origValue = doc['@timestamp'].value;
ZonedDateTime newValue = origValue.plusDays(1);

return newValue;

```

You don't set `Datum+1` to anything. The return value is the new value of the name of the scripted field. Also I would avoid using special characters in that name.

---

<div class="post-metadata">

**Author:** ![Datakids](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/datakids/32/39622_2.png) [@Datakids](https://discuss.elastic.co/u/Datakids)\
**Post date:** [December 14, 2020, 4:59pm UTC](https://discuss.elastic.co/t/add-1-day-to-datefield-kibana-scripted-fields/258595/5 "2020-12-14T16:59:16Z")

</div>

hm, not working  
origValue and newValue ist not recognize by script language (or meant its not "blue")

if I change newValue to just new it change the color to blue  
but what is the right param for origValue ?

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [December 14, 2020, 5:06pm UTC](https://discuss.elastic.co/t/add-1-day-to-datefield-kibana-scripted-fields/258595/6 "2020-12-14T17:06:30Z")

</div>

Here is what I have.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/1/4/1487eedb2c1cbeace630790cffa2fb61c952c7df.png)

When clicking on `Get help with the syntax and preview the results of your script.` at the bottom this is what I am showing.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/d/a/daa477bf5d58dbd97730db474d8c7304e5ec0289.png)

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/8/2/824ad33bfdbf8bba52181571e7bafed10953542b.png)

If there are errors in the script this is where they would show them. What does yours say?

---

<div class="post-metadata">

**Author:** ![Datakids](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/datakids/32/39622_2.png) [@Datakids](https://discuss.elastic.co/u/Datakids)\
**Post date:** [December 14, 2020, 5:47pm UTC](https://discuss.elastic.co/t/add-1-day-to-datefield-kibana-scripted-fields/258595/7 "2020-12-14T17:47:37Z")

</div>

here my error snipet:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/1/516d32b2bb9a83bc8c134bf3d9f6a7cabf6b3eb8.png)

---

<div class="post-metadata">

**Author:** ![aaron-nimocks](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron-nimocks/32/73965_2.png) [@aaron-nimocks](https://discuss.elastic.co/u/aaron-nimocks)\
**Post date:** [December 14, 2020, 5:53pm UTC](https://discuss.elastic.co/t/add-1-day-to-datefield-kibana-scripted-fields/258595/8 "2020-12-14T17:53:50Z")

</div>

Can you put in your query that generates this error also?

Also what does your `Datum` field look like? Can you paste an example.

You might need to use `JodaCompatibleZonedDateTime` vs `ZonedDateTime` according to that error.

---

<div class="post-metadata">

**Author:** ![Datakids](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/datakids/32/39622_2.png) [@Datakids](https://discuss.elastic.co/u/Datakids)\
**Post date:** [December 15, 2020, 9:55am UTC](https://discuss.elastic.co/t/add-1-day-to-datefield-kibana-scripted-fields/258595/9 "2020-12-15T09:55:24Z")

</div>

I didn't think it was that complicated to manage a simple + of whatever value to a date field.

Ok, here is my Logstash mapping:

```
date {
	match => ["Datum", "YYYY-MM-dd"]
	target => "Datum"
}

```

For Datefield comming from file with this format: 2020-12-14

Thats it, no magic in the middle !

I tried a few things like below to become more familar.  
This here works for instance:

```
long timestampLog = doc['Datum'].value.toInstant().toEpochMilli();
long timestampNew = timestampLog;
return timestampNew;

```

But no any addDays or plusDays works!?

Thanks again for any suggestion

---

<div class="post-metadata">

**Author:** ![Datakids](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/datakids/32/39622_2.png) [@Datakids](https://discuss.elastic.co/u/Datakids)\
**Post date:** [December 18, 2020, 11:40am UTC](https://discuss.elastic.co/t/add-1-day-to-datefield-kibana-scripted-fields/258595/10 "2020-12-18T11:40:16Z")

</div>

so for whatever reason +1 on my timefield doesnt work.  
So I managed this by reindex and add a mutate timezone field +1

Thanks anyway for your help

---

<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 15, 2021, 11:40am UTC](https://discuss.elastic.co/t/add-1-day-to-datefield-kibana-scripted-fields/258595/11 "2021-01-15T11:40:34Z")

</div>

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