Spaces:
Runtime error
Runtime error
import streamlit as st | |
import datetime | |
from math import ceil | |
st.write("Find out your 500-day, 1000-day, etc., anniversaries") | |
date_str=st.text_area("Enter a date (format: yyyy-mm-dd): ") | |
today = datetime.datetime.now().date() | |
# Convert the input string to a datetime object | |
try: | |
date = datetime.datetime.strptime(date_str, "%Y-%m-%d") | |
# Calculate the dates 500, 1000, 1500, 2000, and 2500 days after the input date | |
dates_after = [] | |
cutoff=(today - date.date()).days+2001 | |
day_list=list(range(500,2501,500))+list(range(3000,cutoff,1000)) | |
for days in day_list: | |
delta = datetime.timedelta(days=days) | |
dates_after.append(date + delta) | |
# Calculate the next multiple of 500 days after the current date | |
delta_days = 500*(ceil((today - date.date()).days/500)) | |
next_multiple = date + datetime.timedelta(days=delta_days) | |
# Print the results | |
st.write("Input date:", date.strftime("%Y-%m-%d")) | |
st.write("Next multiple of 500:", str(delta_days), "days on", next_multiple.strftime("%Y-%m-%d"),"\n") | |
for i, date_after in enumerate(dates_after): | |
st.write(f"{day_list[i]} days after input date:", date_after.strftime("%Y-%m-%d")) | |
except ValueError: | |
st.write("Write date in format yyyy-mm-dd") |