# How we can calculate only Working days only Monday to Friday and skip Saturday and Sunday

**URL:** <https://discuss.elastic.co/t/how-we-can-calculate-only-working-days-only-monday-to-friday-and-skip-saturday-and-sunday/335731>\
**Category:** Elasticsearch\
**Created:** [June 12, 2023, 3:25am UTC](https://discuss.elastic.co/t/how-we-can-calculate-only-working-days-only-monday-to-friday-and-skip-saturday-and-sunday/335731 "2023-06-12T03:25:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![PappuSingh](https://avatars.discourse-cdn.com/v4/letter/p/ea666f/32.png) [@PappuSingh](https://discuss.elastic.co/u/PappuSingh)\
**Post date:** [June 12, 2023, 3:25am UTC](https://discuss.elastic.co/t/how-we-can-calculate-only-working-days-only-monday-to-friday-and-skip-saturday-and-sunday/335731/1 "2023-06-12T03:25:02Z")

</div>

How we can calculate only Working days only Monday to Friday and skip Saturday and Sunday

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [June 12, 2023, 5:27am UTC](https://discuss.elastic.co/t/how-we-can-calculate-only-working-days-only-monday-to-friday-and-skip-saturday-and-sunday/335731/2 "2023-06-12T05:27:51Z")

</div>

Which time zone do you define the weekdays based on?

I suspect indexing the weekday (as per your definition/time zone) into a separate field at index time and then filter on this would be the by far most performant and scalable method. It _may_ also be possible to create a [runtime field](https://www.elastic.co/guide/en/elasticsearch/reference/8.8/runtime.html) to do this, but I would expect this to be slower.

---

<div class="post-metadata">

**Author:** ![PappuSingh](https://avatars.discourse-cdn.com/v4/letter/p/ea666f/32.png) [@PappuSingh](https://discuss.elastic.co/u/PappuSingh)\
**Post date:** [June 13, 2023, 7:09am UTC](https://discuss.elastic.co/t/how-we-can-calculate-only-working-days-only-monday-to-friday-and-skip-saturday-and-sunday/335731/3 "2023-06-13T07:09:21Z")

</div>

We need to calculate the days based on the Created date which is available under index mapping.  
could you please provide the script for the runtime field?

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [June 13, 2023, 7:23am UTC](https://discuss.elastic.co/t/how-we-can-calculate-only-working-days-only-monday-to-friday-and-skip-saturday-and-sunday/335731/4 "2023-06-13T07:23:52Z")

</div>

Are you determining weekday boundaries based on UTC time?

Note that 2023-06-13T02:00:00.000Z is a Tuesday in UTC time but a Monday in the US while 023-06-13T22:00:00.000Z is a Tuesday in UTC time but a Wednesday in India, so time zone considered does matter.

> [@PappuSingh](#):
>
> could you please provide the script for the runtime field?

I am not even sure it is possible, so would leave that to someone with more date/timestamp scripting experience.

---

<div class="post-metadata">

**Author:** ![PappuSingh](https://avatars.discourse-cdn.com/v4/letter/p/ea666f/32.png) [@PappuSingh](https://discuss.elastic.co/u/PappuSingh)\
**Post date:** [June 21, 2023, 5:21am UTC](https://discuss.elastic.co/t/how-we-can-calculate-only-working-days-only-monday-to-friday-and-skip-saturday-and-sunday/335731/5 "2023-06-21T05:21:21Z")

</div>

Can we calculate with working Days through UTC time zone?

---

<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 19, 2023, 5:22am UTC](https://discuss.elastic.co/t/how-we-can-calculate-only-working-days-only-monday-to-friday-and-skip-saturday-and-sunday/335731/6 "2023-07-19T05:22:06Z")

</div>

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