# Create field DATE - 3 Months ago

**URL:** https://discuss.elastic.co/t/create-field-date-3-months-ago/56290
**Category:** Elasticsearch
**Created:** [July 25, 2016, 12:11pm UTC](https://discuss.elastic.co/t/create-field-date-3-months-ago/56290 "2016-07-25T12:11:44Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![pittoch](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@pittoch](https://discuss.elastic.co/u/pittoch)
#### Post date: [July 25, 2016, 12:11pm UTC](https://discuss.elastic.co/t/create-field-date-3-months-ago/56290/1 "2016-07-25T12:11:44Z")

</div>

In an index, I have a field called date (format: YYYY-MM-DD HH:MM:SS)

How can I create a new field "called Date3M) to have the same date but 3 months ago ?  
Example: Date: 2016-07-05 02:30:54  
Date3M: 2016-04-05 2:30:54

Thanks!

---

<div class="post-metadata">

### Author: ![tobiaswerner](https://avatars.discourse-cdn.com/v4/letter/t/eada6e/32.png) [@tobiaswerner](https://discuss.elastic.co/u/tobiaswerner)
#### Post date: [July 25, 2016, 12:33pm UTC](https://discuss.elastic.co/t/create-field-date-3-months-ago/56290/2 "2016-07-25T12:33:22Z")

</div>

If you need to store the field I think you have to use any kind of scripting.

---

<div class="post-metadata">

### Author: ![pittoch](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@pittoch](https://discuss.elastic.co/u/pittoch)
#### Post date: [July 27, 2016, 11:33am UTC](https://discuss.elastic.co/t/create-field-date-3-months-ago/56290/3 "2016-07-27T11:33:29Z")

</div>

there is no other solution with Lucene ?

---

<div class="post-metadata">

### Author: ![tobiaswerner](https://avatars.discourse-cdn.com/v4/letter/t/eada6e/32.png) [@tobiaswerner](https://discuss.elastic.co/u/tobiaswerner)
#### Post date: [July 27, 2016, 2:42pm UTC](https://discuss.elastic.co/t/create-field-date-3-months-ago/56290/4 "2016-07-27T14:42:43Z")

</div>

I don't think so, maybe someone else have any ideas...?

What do you want to achive? You probably can do the date math in your injection pipeline...

---

<div class="post-metadata">

### Author: ![Kamil\_Hurajt](https://avatars.discourse-cdn.com/v4/letter/k/49beb7/32.png) [@Kamil\_Hurajt](https://discuss.elastic.co/u/Kamil_Hurajt)
#### Post date: [July 27, 2016, 3:13pm UTC](https://discuss.elastic.co/t/create-field-date-3-months-ago/56290/5 "2016-07-27T15:13:00Z")

</div>

In this case you can use script field in your query

`"script_fields" : { "myField" : { "script" : "doc['my_field_name'].value * 2" } }`

Where you can define what should happen, let's say that you storing date in timestamp then you can do this:

"script\_fields" : {  
"date3m" : {  
"script" : "doc['date'].value - 3_24_60\*60"  
}  
}

---

<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: [July 5, 2017, 10:32pm UTC](https://discuss.elastic.co/t/create-field-date-3-months-ago/56290/6 "2017-07-05T22:32:27Z")

</div>


