Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from datetime import datetime, date
|
| 3 |
+
|
| 4 |
+
# Page config
|
| 5 |
+
st.set_page_config(page_title="Age Calculator", page_icon="๐
")
|
| 6 |
+
|
| 7 |
+
st.title("๐
Age Calculator App")
|
| 8 |
+
st.markdown("Enter your birthdate to calculate your current age in years, months, and days.")
|
| 9 |
+
|
| 10 |
+
# Input: Date of birth
|
| 11 |
+
birth_date = st.date_input("Select your birthdate", min_value=date(1900, 1, 1), max_value=date.today())
|
| 12 |
+
|
| 13 |
+
# Button to calculate age
|
| 14 |
+
if st.button("Calculate Age"):
|
| 15 |
+
today = date.today()
|
| 16 |
+
|
| 17 |
+
# Calculate years, months, days
|
| 18 |
+
years = today.year - birth_date.year
|
| 19 |
+
months = today.month - birth_date.month
|
| 20 |
+
days = today.day - birth_date.day
|
| 21 |
+
|
| 22 |
+
# Adjust if negative
|
| 23 |
+
if days < 0:
|
| 24 |
+
months -= 1
|
| 25 |
+
days += (date(today.year, today.month, 1) - date(today.year, today.month - 1, 1)).days
|
| 26 |
+
|
| 27 |
+
if months < 0:
|
| 28 |
+
years -= 1
|
| 29 |
+
months += 12
|
| 30 |
+
|
| 31 |
+
# Output
|
| 32 |
+
st.success(f"๐ You are **{years} years, {months} months, and {days} days** old.")
|