# Access timepicker range from within visualization plugin

**URL:** <https://discuss.elastic.co/t/access-timepicker-range-from-within-visualization-plugin/63424>\
**Category:** Kibana\
**Created:** [October 19, 2016, 4:58pm UTC](https://discuss.elastic.co/t/access-timepicker-range-from-within-visualization-plugin/63424 "2016-10-19T16:58:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![nathanc](https://avatars.discourse-cdn.com/v4/letter/n/e68b1a/32.png) [@nathanc](https://discuss.elastic.co/u/nathanc)\
**Post date:** [October 19, 2016, 4:58pm UTC](https://discuss.elastic.co/t/access-timepicker-range-from-within-visualization-plugin/63424/1 "2016-10-19T16:58:27Z")

</div>

I am trying to access the queried date range from within a plugin, so that I can do calculations based on the length of time being queried. Is there a way to do this?

For example, I may have an aggregated sum of hits and I want to calculate the average number of hits per second and display that number in the visualization.

---

<div class="post-metadata">

**Author:** ![lukas](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas/32/6812_2.png) [@lukas](https://discuss.elastic.co/u/lukas)\
**Post date:** [October 19, 2016, 6:22pm UTC](https://discuss.elastic.co/t/access-timepicker-range-from-within-visualization-plugin/63424/2 "2016-10-19T18:22:20Z")

</div>

Hi Nathan!

If you are using Angular, then `timefilter` is an available service.

Here's where the `timefilter` is defined: [http://github.com/lukasolson/kibana/blob/master/src/ui/public/timefilter/timefilter.js#L48](http://github.com/lukasolson/kibana/blob/master/src/ui/public/timefilter/timefilter.js#L48)

And here's an example of how to use it: [https://github.com/lukasolson/kibana/blob/master/src/core\_plugins/kibana/public/dashboard/index.js#L56](https://github.com/lukasolson/kibana/blob/master/src/core_plugins/kibana/public/dashboard/index.js#L56)

I'd suggest using `timefilter.getBounds()` to accomplish what you're trying to do.

---

<div class="post-metadata">

**Author:** ![nathanc](https://avatars.discourse-cdn.com/v4/letter/n/e68b1a/32.png) [@nathanc](https://discuss.elastic.co/u/nathanc)\
**Post date:** [October 20, 2016, 2:52pm UTC](https://discuss.elastic.co/t/access-timepicker-range-from-within-visualization-plugin/63424/3 "2016-10-20T14:52:51Z")

</div>

Thank you very much! I was able to get the length of time with:  
`var ms = Date.parse($scope.timefilter.getBounds().max._d) - Date.parse($scope.timefilter.getBounds().min._d);`

---

<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 6, 2017, 1:36pm UTC](https://discuss.elastic.co/t/access-timepicker-range-from-within-visualization-plugin/63424/4 "2017-07-06T13:36:08Z")

</div>


