# Make a simple countdown to date

Hi there,
As noticed in title, I try to make a simple countdown to date in TD in two simple steps :

• Enter a date and hours
• Make a countdown to this date, using computer time, and showing days, hours, minutes and seconds.
• Trigger an action when everything has reached 0
I was able to make a basic to NYE, as is it the most simple to do. Still trying to figure out how to easly change the target date / hours.
Any help will be very appreciated ! Thanks

Hi @zerozero,

theoretically the Clock CHOP can be useful for this. The idea is to use the Fraction of a year as an output mode and then subtract todays date (as in year fraction) from the set date’s year fraction. Finally you can pass that back into a Clock CHOP to retrieve days, hours, sec, and more.
This get’s a bit more complicated if you are looking at dates past the current year, but should be still possible by adding the number of years to the final fraction.
For some examples this seems to work - with further in the future dates, this seems to be broken at the moment unfortunately with the hours not being correctly calculated from what i could see…

countdown.tox (7.8 KB)

So the safest bet might be python:

``````from datetime import datetime

def isLeapYear(year):
return year % 4 == 0 and (year % 100 != 0 or year % 400 == 0)

def countdown(targetDate):
now = datetime.now()
diff = targetDate - now

minutes = diff.totalSeconds() / 60
hours = minutes / 60
days = hours / 24
weeks = days / 7

# Calculate the number of leap years and non-leap years
leapYears = sum(isLeapYear(year) for year in range(now.year, targetDate.year + 1))
nonLeapYears = (targetDate.year - now.year + 1) - leapYears

years = (leapYears * 366 + nonLeapYears * 365) / 365.25
months = years * 12

return {
'minutes': int(minutes),
'hours': int(hours),
'days': int(days),
'weeks': int(weeks),
'months': int(months),
'years': int(years)
}

# Usage:
targetDate = datetime(2023, 12, 31)
debug(countdown(target_date))
``````

you would have to call this every second or every minute (depending on your countdown)

cheers
Markus