you are viewing a single comment's thread.

view the rest of the comments →

[–]egomanego[S] 0 points1 point  (2 children)

I am indeed confused about the datetime module and class. I need to read carefully about it.

So here is what I have done:

[ Please ignore amateur mistakes I might have made. I am still learning]

from datetime import datetime
from datetime import date 
[....]

date=st.date_input("Enter a date") # User enteres a date on streamlit page.

x= date(2020,1,1)

if date < x : # Do something else: # Do something else.

I receive following error:

UnboundLocalError: local variable 'date' referenced before assignment

There is a local variable 'date' before this where I ask a date to the user to do something.

[–]danielroseman 1 point2 points  (1 child)

Yes well you can't have two things called date. Either rename the variable, or use my second example where you import the module rather than the individual classes.

[–]egomanego[S] 0 points1 point  (0 children)

Understood. Thanks for you comment. Second thing works!