Date_input not updating his value

im new to streamlit and to programming in general.
i wanted to use a date_input with the objective of colecting an user age, and if it is less than 18 years old it gives an error, the problem is that the value of the date_input doesnt change from its initial value, can anyone help me?

this is the code im using:

import streamlit as st
import datetime

def check_age(birth_date: date):
today = date.today()
age = today.year - birth_date.year - ((today.month, today.day) < (birth_date.month, birth_date.day))
return age>=18

birthDate = st.date_input(“Birthday”, format=“DD/MM/YYYY”,value=None, max_value=date.today(), min_value=date(1900, 1, 1))
st.write(birthDate)
if birthDate != None:
if check_age(birthDate):
st.write(“Please note that this will be checked further”)
else:
st.error(“You must be 18 or older to sign in(Please note that this will be checked further)”)

Hello Tom!
I think you didn’t import datetime properly; it should be: from datetime import date. I recreated your code:

import streamlit as st
from datetime import date

def check_age(birth_date: date):
    today = date.today()
    age = today.year - birth_date.year - ((today.month, today.day) < (birth_date.month, birth_date.day))
    return age>=18

birthDate = st.date_input("Birthday",
                          format="DD/MM/YYYY",
                          value=None,
                          max_value=date.today(),
                          min_value=date(1900, 1, 1))

st.write(birthDate)
if birthDate != None:
    if check_age(birthDate):
        st.write("Please note that this will be checked further")
    else:
        st.error("You must be 18 or older to sign in(Please note that this will be checked further)")

And it worked as you specified, I think.

Hello Carlos, thanks for your help, i have rewrited my code with what you said and the problem is not fixed.
As you saw in the script, the initial value of “birthDate” is None, and after the users inputs a date, it continues to be None, or at least the st.write(birthDate) continues to show None.
If it helps, im using visual studio code.

Hey Tom, look, it worked for me:


I ran the server :
streamlit run app.py
Nothing special; I’m just using a virtual environment in python,
How did you run the server?
I hope it helps!

In the main code it doesnt work but when i put all the parts in a different script and run it it works, and im only copying from my code, its strange