# How to create new field after subtracting 2 date time field

**URL:** <https://discuss.elastic.co/t/how-to-create-new-field-after-subtracting-2-date-time-field/329822>\
**Category:** Elasticsearch\
**Created:** [April 12, 2023, 10:08am UTC](https://discuss.elastic.co/t/how-to-create-new-field-after-subtracting-2-date-time-field/329822 "2023-04-12T10:08:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rkidev](https://avatars.discourse-cdn.com/v4/letter/r/e95f7d/32.png) [@rkidev](https://discuss.elastic.co/u/rkidev)\
**Post date:** [April 12, 2023, 10:08am UTC](https://discuss.elastic.co/t/how-to-create-new-field-after-subtracting-2-date-time-field/329822/1 "2023-04-12T10:08:19Z")

</div>

I want to create one new field type String in existing index after subtracting two datetime (format - 2023-04-31 23:23:13). It should return 'Type-1' if seconds difference is more than or equal to 180 and should return 'Type-2' if seconds difference is less than 180.

---

<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 10, 2023, 10:09am UTC](https://discuss.elastic.co/t/how-to-create-new-field-after-subtracting-2-date-time-field/329822/2 "2023-05-10T10:09:05Z")

</div>

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