Date slider?

Is there a date slider widget?

I couldn’t find one, so I use a float slider with a range from 0 to 1 and convert that then to the min and max dates of the dataframe df:

sl_sd = st.sidebar.slider("Start date",0.0,1.0, value=0)
sd = date_from_slider(sl_sd)
st.sidebar.markdown(f"Start date: **{str_from_date(sd)}**")

def date_from_slider(sl):
    return (df.index.max()-df.index.min())*sl + df.index.min()

def str_from_date(d):
    return pd.Timestamp(d).strftime("%d-%m-%Y")

This is obviously not as nice as a real date slider widget because all the labelling is for the range 0-1 not for the dates.

1 Like

Hey @halloleo,

I just merged a PR that’ll provide a similar functionality! Instead of a slider we’ve updated the date_input to accept a range. This should be coming out soon in a future release.

All you need to do is pass in a list with up to 2 values. Hopefully this works for your needs!

d3 = st.date_input("range, no dates", [])

d3 = st.date_input("Range, one date", [, 7, 6)])

d5 = st.date_input("date range without default", [, 7, 6),, 7, 8)])

Hello, sorry I am very new to git and python. How can I update my streamlit to use your updated feature?
I installed my streamlit on conda with pip install streamlit
Thank you!

Hi @doraemon123

  • if you are patient, you can wait for the next Streamlit release which is 0.61 then you will be able to update streamlit with pip install -U streamlit.
  • if you are not patient you can try the nightly build, which requires you to uninstall Streamlit pip uninstall streamlit and install the nightly build pip install streamlit-nightly in your conda env. This is a little more involved and though there should not be any problems, I recommend you instead create a new conda environment and install streamlit-nightly there so you have your normal Streamlit environment and a new cutting-edge Streamlit environment with the new date-picker :wink: .

BTW @karriebear this looks awesome :slight_smile:


Thank you very much @andfanilo :grinning:

1 Like

Hi all.

I was eagerly awaiting a date range option, too. I just tried the new 0.61 version and date range picker. It works, but for multi-month ranges it feels awkward.

Is there a simple slider object with dates instead of floats possible/ in the pipeline?


Hey @cwerner,

We have a feature request to enable datetime formatting on the slider. This has not been prioritized on our roadmap yet. Feel free to +1 it.