String formatting for slider - example

Hi,

I am looking to use a slider for an app to provide lower and upper dates on a parameter. Since st.slider only supports floats, I first convert my dates to timestamp, with the idea of using the format parameter in the st.slider to show something understandable to the user.

However, I cannot seem to find an example of how this is done. For now, I have the following code:

st.slider("Plotting window", 
    value=(min(list_of_days).timestamp(), max(list_of_days).timestamp()), 
    format='%s'.format(datetime.utcfromtimestamp().strftime('%d/%m/%y')))

where list_of_days is, well, a list of days. This does not run since the utcfromtimestamp() needs an input parameter, i.e. the value that is to be converted. How can I get that?

I think it might be good to include an example in the API reference guide (or even better, enable support for datetime? :slight_smile: ).

Thanks
Richard

Hi Richard,

Would something like this work for you?

import streamlit as st
start_date = st.date_input(“Start Date”)
end_date = st.date_input(“End Date”)

Thanks!

Hi Negmat,

thanks for your interest!

What you suggested works, however, I would prefer:

Thanks
Richard

Hi @RichardOberdieck,

This is not currently possible as the format parameter accepts the following

        format : str or None
            Printf/Python format string controlling how the interface should
            display numbers. This does not impact the return value.

Feel free to file a github issue for this functionality!

Can we please get an example of a st.slider function with the format argument filled in with something?