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

Hey, is there anyway to add a frame readout instead of milliseconds? Im currently assuming not, as thats not part of normal “clock” data.Alternatively I was trying to run timecode in reverse, but of course that doesnt show “days”.

Im trying to create a countdown but the client wants to see frames as part of the readout, which brings me into my second puzzle - making the readout friendly. Currently using ChopTo->Reorder->Select->Text, then manual text boxes with colons and all dropped into Layout but the spacing is far too big at the moment.

Hi @wheelhouse,

The Timecode CHOP can take an input with channels negative, hour, minute, second, frame specified. In addition it can also output Total Frames and Countdown Channels. So if you set the negative channel to 1 and for hour, minute, second specify the delta time you want to run, you can get the total frames to that point in time. Select the Countdown Frames channel and rename it to frame and select that CHOP/channel as the CHOP source for another Timecode CHOP, you will get a Countdown timecode which you can also reference via its timecode object in a Text TOP or COMP.

cheers
Markus

k