# Can we subtract Date time range with another?

**URL:** <https://forum.bubble.io/t/can-we-subtract-date-time-range-with-another/296109>\
**Category:** Questions\
**Created:** [December 4, 2023, 8:10am UTC](https://forum.bubble.io/t/can-we-subtract-date-time-range-with-another/296109 "2023-12-04T08:10:44Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdburhan3](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mdburhan3/32/136126_2.png) [@mdburhan3](https://forum.bubble.io/u/mdburhan3)\
**Post date:** [December 4, 2023, 8:10am UTC](https://forum.bubble.io/t/can-we-subtract-date-time-range-with-another/296109/1 "2023-12-04T08:10:44Z")

</div>

Hello Everyone 👋

Is it possible to subtract the Date time range from another?

For example, I’ve a date range like this  
[“Nov 30, 2023 10:30 am”,“Nov 30, 2023 14:00 pm”]

Can we subtract another date range like [“Nov 30, 2023 11:30 am”,“Nov 30, 2023 12:00 pm”] from the above range 👆  
&  
Generate two time ranges like this 👇  
[“Nov 30, 2023 10:30 am”,“Nov 30, 2023 11:30 pm”] and  
[“Nov 30, 2023 12:30 am”,“Nov 30, 2023 14:00 pm”]

If yes, any idea how to do that?

Thanks a lot for your help 🙏

---

<div class="post-metadata">

**Author:** ![nico.dicagno](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/nico.dicagno/32/207961_2.png) [@nico.dicagno](https://forum.bubble.io/u/nico.dicagno)\
**Post date:** [December 4, 2023, 1:12pm UTC](https://forum.bubble.io/t/can-we-subtract-date-time-range-with-another/296109/2 "2023-12-04T13:12:58Z")

</div>

Using a custom javascript function would work quite well here, as this would probably be just a few lines of code.  
But you can also set this up with native bubble with a few workflow steps.

Is it guaranteed that Date Range B is always fully contained by Date Range A? Or could it be partially contained? Or could it also be fully outside?

If the latter two scenarios are allowed, what would you want your output to look like?

---

<div class="post-metadata">

**Author:** ![sudsy](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/sudsy/32/114637_2.png) [@sudsy](https://forum.bubble.io/u/sudsy)\
**Post date:** [December 4, 2023, 2:54pm UTC](https://forum.bubble.io/t/can-we-subtract-date-time-range-with-another/296109/3 "2023-12-04T14:54:34Z")

</div>

Hi @mdburhan3,

If I understand correctly, you have two date ranges - one of which is entirely contained within the other - and you want to effectively “remove” the contained date range from the containing date range, thereby resulting in two new date ranges.

Yes, that’s totally possible; and in fact, it’s quite easy. You might want to familiarize yourself with [Bubble’s built-in date range operations](https://manual.bubble.io/core-resources/data/operations-and-comparisons#date-range-type).

For the specific scenario you describe, you’d simply create two new ranges as follows:

- First range would be `containing_range:start <- range -> contained_range:start`
- Second range would be `contained_range:end <- range -> containing_range:end`

You’d probably want to first check to ensure one range is entirely contained within the other. Bubble has lots of super handy and efficient date related operations.

---

<div class="post-metadata">

**Author:** ![mdburhan3](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mdburhan3/32/136126_2.png) [@mdburhan3](https://forum.bubble.io/u/mdburhan3)\
**Post date:** [December 4, 2023, 3:29pm UTC](https://forum.bubble.io/t/can-we-subtract-date-time-range-with-another/296109/4 "2023-12-04T15:29:07Z")

</div>

Thanks a lot @sudsy  
I will try this & Let you know

---

<div class="post-metadata">

**Author:** ![mdburhan3](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mdburhan3/32/136126_2.png) [@mdburhan3](https://forum.bubble.io/u/mdburhan3)\
**Post date:** [December 4, 2023, 3:30pm UTC](https://forum.bubble.io/t/can-we-subtract-date-time-range-with-another/296109/5 "2023-12-04T15:30:37Z")

</div>

Thanks for your reply  
Yes it is always fully contained

I will try to implement sudsy response first

---

<div class="post-metadata">

**Author:** ![mdburhan3](https://sea1.discourse-cdn.com/bubble/user_avatar/forum.bubble.io/mdburhan3/32/136126_2.png) [@mdburhan3](https://forum.bubble.io/u/mdburhan3)\
**Post date:** [December 4, 2023, 4:53pm UTC](https://forum.bubble.io/t/can-we-subtract-date-time-range-with-another/296109/6 "2023-12-04T16:53:24Z")

</div>

Thanks a lot It works 🙏
