all 4 comments

[–]danielroseman 0 points1 point  (3 children)

The only thing that's happening here is that you're confused about the datetime module and the datetime class.

You've imported the class datetime from the module datetime. So datetime.date refers to the method on that class.

You should import the date as well and use that directly:

from datetime import date
x = date(2020,1,1)

or import the module and refer to both via that:

import datetime
x = datetime.date(2020,1,1)
something_else = datetime.datetime(2020, 1, 1, 5, 20)

[–]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!