# Make a time IntervalSlider

I want to make a time interval slider with an initial setting of (10:00:00 Mar. 8 2015, 12:30:00 Mar. 8 2015) and which varies from 00:00:00 Mar. 8 2015 to 22:30:00 Mar. 8 2015 with a granularity of 5 Minutes.

I tried using IntervalSlider in Mathematica 10 like this:

IntervalSlider[{DateString[{2015, 3, 8, 10, 0, 0.}],
DateString[{2015, 3, 8, 12, 30, 0.}]}, {DateObject[{2015, 3, 8, 0,
0, 0.}], DateObject[{2015, 3, 8, 22, 30, 0.}],
Quantity[5, "Minutes"]}]


but it doesn't work. Any ideas?

You will need work with an interval slider in terms of AbsoluteTime values because such sliders only work with numeric objects. Here is a demonstration where a interval slider has the behavior you want.

With[{
min0 = AbsoluteTime @ DateObject[{2015, 3, 8, 10, 0, 0.}],
max0 = AbsoluteTime @ DateObject[{2015, 3, 8, 12, 30, 0.}],
minT = AbsoluteTime @ DateObject[{2015, 3, 8, 0, 0, 0.}],
maxT = AbsoluteTime @ DateObject[{2015, 3, 8, 22, 30, 0.}]},
Manipulate[
DateString /@ span,
{{span, {min0, max0}, "Interval"}, minT, maxT, 5 60,
ControlType -> IntervalSlider}]]


• Cool! It is done. Apr 1, 2015 at 9:10

In version 10.1, try this:

Manipulate[
TimelinePlot[
{Interval[{ToString[myBegin], ToString[myEnd]}] -> "My range"},
PlotRange -> {DateObject[{1940}], DateObject[{2020}]},
Ticks -> {DateRange["1940", "2020", Quantity[5, "Years"]]}
],
{{myBegin, 1950, "Begin"}, 1950, 2014, 1},
{{myEnd, 1960, "End"}, myBegin, 2015, 1}]

• +1, but note as Begin slider increases, the DateTicks start to overlap. Maybe you can answer my Q: mathematica.stackexchange.com/questions/78821/… Apr 1, 2015 at 22:33
• @alancalvitti I think there must be a bug in TimelinePlot which prevents the "obvious" implementation of PlotRange. (I just got 10.1 an hour ago, so haven't explored all the power and limitations of TimelinePlot. However, Ticks->All in my example prevents overlapping (but marks by seconds). Apr 1, 2015 at 22:36
• @alancalvitti I figured it out. See my revised solution. Apr 1, 2015 at 22:54