Slider does not work with dates older than 1st february 1970

Hello guys, I tried to deploy a custom slider in my streamlit app and what happens is very strange, the slider works with dates after 1st of February 1970, but when an older date is passed it gives the following error:

The code of the properly working slider bar is (note: gp.m2_usa is a DataFrame imported from other file)

format = 'MMM DD, YYYY'  # format output
        start_date = gp.m2_usa.index[132].date() #Here the start date is 1970-02-01
        end_date = gp.m2_usa.index[-1].date() #Here the end date is 2021-06-01
        slider = st.slider('Select date', min_value=start_date, value=end_date, max_value=end_date, format=format)

Here the slider works properly

But if I choose just one older index as in this code:

format = 'MMM DD, YYYY'  # format output
        start_date = gp.m2_usa.index[131].date() #Here the start date is 1970-01-01
        end_date = gp.m2_usa.index[-1].date() #Here the end date is 2021-06-01
        slider = st.slider('Select date', min_value=start_date, value=end_date, max_value=end_date, format=format)

It raises the following error:

Thank you in advance for all your help!

1 Like

Hi @beautiful_blood

Something seems to be wrong with your min_value variable.

Can you please share the related code, so I can try to debug on my machine?

Thanks
Charly

1 Like

First of all thank you very much for your help!

I uploaded the code with the mistake to my repo in order you maybe can clone it and make a quicker debug!

Please, find it here: https://github.com/Serrat96/moneyprintersgobrr

1 Like

Thanks!

By the way, have you checked that error:

https://www.google.com/search?q=errno+22+invalid+argument+datetime&oq=erno22&aqs=chrome.2.69i57j0i13l9.2708j1j7&sourceid=chrome&ie=UTF-8

1 Like

Iā€™ve been investigating and as far as I can see the problem is the conversion from ā€œhuman dateā€ to ā€œepoch timestampā€. It seems that in 1970-01-01 00:00:00 the conversion to ā€œepoch timestampā€ returns zero:

And for older dates returns negative values. It seems that the conversor is unable (I donā€™t know for what reason) to work with zero or negative values of ā€œepoch timestampā€. If for example i go back one day the time is negative as you can see in this picture:

I will keep investigating. I donā€™t know whatā€™s ā€œepoch timestampā€ and whatā€™s the problem with it being zero or negative.

Hope we can find a solution soon!

1 Like

Ok. As far as I can see Windows is unable to work with zero or negative ā€œepoch timestampā€. The only thing I can think of is, as I see you @Charly_Wargnier are Streamlit staff is to contact with Streamlit developers in order to make the necessary changes to avoid the slider working with that ā€œepoch timestampā€ time formatā€¦

In other operative systems as Mac or Linux, the OS is capable to work with that negative ā€œepoch timestampā€ but it seems Windows canā€™tā€¦

Maybe thereā€™s another easier and simple solution, but at the moment this is the conclusion I got. In case the Streamlit team has a better solution I would be very pleased of implement it.

Thank you very much for all your time. At the moment, instead of the slider, I will make a date selector with st.date_input as it seems has no problem working with older than 1970-01-01 dates.

1 Like

Thanks @beautiful_blood

Iā€™ll share with Devs now.

Best,
Charly

1 Like

Thank you for all your time and interest in the issue!

Hope to hear from you the developerā€™s response if possible!

Best wishes for all of you!

1 Like

Hello @Charly_Wargnier just FYI, I tried the code on a MacBook and it works perfectly. So a 100% itā€™s a Windows problem.

Thank you very much for all your time and attention!

1 Like

Youā€™re very welcome!

Glad you managed to make it work by switching platform. :slight_smile:

Happy Streamlitinā€™! :balloon::raised_hands:

Best,
Charly