# How to subtract TimeSpan in ticks from datetime in any type of query range or script

**URL:** <https://discuss.elastic.co/t/how-to-subtract-timespan-in-ticks-from-datetime-in-any-type-of-query-range-or-script/253807>\
**Category:** Elasticsearch\
**Created:** [October 30, 2020, 11:29am UTC](https://discuss.elastic.co/t/how-to-subtract-timespan-in-ticks-from-datetime-in-any-type-of-query-range-or-script/253807 "2020-10-30T11:29:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sameer\_sawant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sameer_sawant/32/78150_2.png) [@sameer\_sawant](https://discuss.elastic.co/u/sameer_sawant)\
**Post date:** [October 30, 2020, 11:29am UTC](https://discuss.elastic.co/t/how-to-subtract-timespan-in-ticks-from-datetime-in-any-type-of-query-range-or-script/253807/1 "2020-10-30T11:29:49Z")

</div>

I want to achive something like this `endDateUtc.Subtract(timespan) <= DateTime.Now `in elastic query . both fields ( enddateutc and timespan ) available in document. i want to do something like `doc["enddateutc"].value - doc["timespan"].value <= Datetime.now` , but since timespan is in ticks. i am not able to subtract. Appreciate any 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:** [November 27, 2020, 11:29am UTC](https://discuss.elastic.co/t/how-to-subtract-timespan-in-ticks-from-datetime-in-any-type-of-query-range-or-script/253807/2 "2020-11-27T11:29:56Z")

</div>

Closed on November 27, 2020, 11:29am UTC

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