# Date Histogram when only have start and end dates (or duration)?

**URL:** https://discuss.elastic.co/t/date-histogram-when-only-have-start-and-end-dates-or-duration/34726
**Category:** Elasticsearch
**Created:** [November 16, 2015, 8:07pm UTC](https://discuss.elastic.co/t/date-histogram-when-only-have-start-and-end-dates-or-duration/34726 "2015-11-16T20:07:40Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![twigbranch](https://avatars.discourse-cdn.com/v4/letter/t/2bfe46/32.png) [@twigbranch](https://discuss.elastic.co/u/twigbranch)
#### Post date: [November 16, 2015, 8:07pm UTC](https://discuss.elastic.co/t/date-histogram-when-only-have-start-and-end-dates-or-duration/34726/1 "2015-11-16T20:07:40Z")

</div>

I'd like to plot the number of car trips ongoing on a particular day, every day for the last week. I know the start time and end time of the trips - the trips can last less than a day, or more than a day. Ultimately, I will allow the user to set the interval size (i.e. from every day, to every two days, etc.) and the date range (i.e. from the last week, to the last two weeks, etc.).

It looks like date histogram aggregation might help, but it appears to, in addition to the interval size, take a single date field from which to aggregate into buckets. In my case, as I only have the start and end times, I'd need some way for the histogram aggregator to calculate, based on start and end times, whether a given trip fits into a given interval bucket. Also, a given trip would potentially need to be counted in multiple buckets.

What's the best way to do this?

---

<div class="post-metadata">

### Author: ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)
#### Post date: [November 17, 2015, 9:42am UTC](https://discuss.elastic.co/t/date-histogram-when-only-have-start-and-end-dates-or-duration/34726/2 "2015-11-17T09:42:11Z")

</div>

You might find the following link helpful for this. It is a very similar use-case:

> [@Display concurrency in data on Kibana](https://discuss.elastic.co/t/display-concurrency-in-data-on-kibana/26006):
>
> I have fields with start date and duration (seconds) representing start and duration of a phone call. I would like to define concurrency (a number) when the same destination (also a field) is active within the same duration. That is if a ncall starts now for 30 seconds and another call to the same destination starts 15 seconds into the first call, concurrency should be 2 for the remaining 15 seconds. How do I define this in Kibana visualization as a line graph over time?

Specifically this post in the topic, but I recommend reading the whole topic to get context: [Display concurrency in data on Kibana - #3 by colings86](https://discuss.elastic.co/t/display-concurrency-in-data-on-kibana/26006/3)

---

<div class="post-metadata">

### Author: ![twigbranch](https://avatars.discourse-cdn.com/v4/letter/t/2bfe46/32.png) [@twigbranch](https://discuss.elastic.co/u/twigbranch)
#### Post date: [November 17, 2015, 5:28pm UTC](https://discuss.elastic.co/t/date-histogram-when-only-have-start-and-end-dates-or-duration/34726/3 "2015-11-17T17:28:58Z")

</div>

Beautiful! Thank you very much!

---

<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, 11:37pm UTC](https://discuss.elastic.co/t/date-histogram-when-only-have-start-and-end-dates-or-duration/34726/4 "2017-07-05T23:37:52Z")

</div>


