How do I create a duration timer on my dashboard

I want a measurement on my dashboard that shows the elapsed time since a date. I have been trying to do this with a Python input:

from datetime import datetime

# Get the current date
current_date = datetime.now()

# Define the start date
start_date = datetime(2023, 9, 7)

# Calculate the difference in days
days_difference = (current_date - start_date).days

# Convert days to weeks (1 week = 7 days)
weeks_since = days_difference / 7.0

return {0: weeks_since}

This works but after the Max Age expires I get “MAX AGE EXCEEDED”
So I tried adding a timer:

import time
from datetime import datetime

# Infinite loop to run the code continuously
while True:
    # Get the current date
    current_date = datetime.now()

    # Define the start date
    start_date = datetime(2023, 9, 7)

    # Calculate the difference in days
    days_difference = (current_date - start_date).days

    # Convert days to weeks (1 week = 7 days)
    weeks_since = days_difference / 7.0

    result = {0: weeks_since}

    # Sleep for 30 seconds before the next iteration
    time.sleep(30)

But still doesn’t work.
How would I do this?

Why not just increase the max age setting value?

1 Like