• | **Year countdown timer expression problem**
on Sep 16, 2017 at 10:58:21 am |

I'm trying to create a timer that countdown from 1 year and displays in years, months, days, minutes and seconds. I found a suitable expression on an adobe forum but when run it populates the day, minute and second fields with NA. The expression is below. Any help in getting this to work would be gratefully received. As you can guess I know just enough about expressions to make myself look stupid.

`totalTimeInSeconds = 31400000;`

secondsPerMinute = 60;

secondsPerHour = 60 * 60;

secondsPerDay = 60 * 60 * 24;

secondsPerMonth = 60 * 60 * 24 * 30;

secondsPerYear = 60 * 60 * 24 * 30 * 12;

secondsRemaining = totalTimeInSeconds;

years = Math.floor(secondsRemaining / secondsPerYear);

secondsRemaining = secondsRemaining % years;

months = Math.floor(secondsRemaining / secondsPerMonth);

secondsRemaining = secondsRemaining % months;

days = Math.floor(secondsRemaining / secondsPerDay);

secondsRemaining = secondsRemaining % days;

hours = Math.floor(secondsRemaining / secondsPerHour);

secondsRemaining = secondsRemaining % hours;

minutes = Math.floor(secondsRemaining / secondsPerMinute);

secondsRemaining = secondsRemaining % minutes;

seconds = secondsRemaining;

txt = "";

txt += yearleadingZeros(years);

txt += leadingZeros(months);

txt += leadingZeros(days);

txt += leadingZeros(hours);

txt += leadingZeros(minutes);

txt += leadingZeros(seconds);

txt;

function yearleadingZeros(i){

x = "0" + Math.floor(i);

return x;

}

function leadingZeros(i){

x = "0" + Math.floor(i);

x = ":" + x.substr(x.length-2, 2);

return x;

}

• | **Re: Year countdown timer expression problem** on Sep 18, 2017 at 6:26:50 am |

The aN is from the NaN error, which means Not a Number. That is because by the time you get to the days you already are trying to do 0%0, which does not have a result. The problem is that you use the number of years, months, etc in your % operation. This should work.`totalTimeInSeconds = 31400000;`

secondsPerMinute = 60;

secondsPerHour = 60 * 60;

secondsPerDay = 60 * 60 * 24;

secondsPerMonth = 60 * 60 * 24 * 30;

secondsPerYear = 60 * 60 * 24 * 30 * 12;

secondsRemaining = totalTimeInSeconds;

years = Math.floor(secondsRemaining / secondsPerYear);

secondsRemaining = secondsRemaining % secondsPerYear;

months = Math.floor(secondsRemaining / secondsPerMonth);

secondsRemaining = secondsRemaining % secondsPerMonth ;

days = Math.floor(secondsRemaining / secondsPerDay);

secondsRemaining = secondsRemaining % secondsPerDay ;

hours = Math.floor(secondsRemaining / secondsPerHour);

secondsRemaining = secondsRemaining % secondsPerHour;

minutes = Math.floor(secondsRemaining / secondsPerMinute);

secondsRemaining = secondsRemaining % secondsPerMinute ;

seconds = secondsRemaining;

txt = "";

txt += yearleadingZeros(years);

txt += leadingZeros(months);

txt += leadingZeros(days);

txt += leadingZeros(hours);

txt += leadingZeros(minutes);

txt += leadingZeros(seconds);

txt;

function yearleadingZeros(i){

x = "0" + Math.floor(i);

return x;

}

function leadingZeros(i){

x = "0" + Math.floor(i);

x = ":" + x.substr(x.length-2, 2);

return x;

}

Andrei

• | **Re: Year countdown timer expression problem** on Sep 19, 2017 at 6:22:44 pm |

Thanks Andrei, I really appreciate you taking the time to look at this. It now displays numbers instead of NA! Unfortunately it doesn't count down when I run it. Would you have any idea why that is?

• | **Re: Year countdown timer expression problem** on Sep 19, 2017 at 6:52:28 pm |

Sorry! It's been a long day, I realised I had hard coded the time to a single variable so the expression is unable to count up or down. I altered the expression as below and it appears to do what I want, at least I can render it out and then reverse it in premiere to do what I want. Thanks again for your help Andrei.

`countspeed = 100;`

clockStart = 31102010;

function times(n){

if (n < 10) return "0" + n else return "" + n

}

clockTime = clockStart +countspeed*(time - inPoint);

if (clockTime < 0){

minus = "-";

clockTime = -clockTime;

}else{

minus = "";

}

totalTimeInSeconds=clockTime

;

secondsPerMinute = 60;

secondsPerHour = 60 * 60;

secondsPerDay = 60 * 60 * 24;

secondsPerMonth = 60 * 60 * 24 * 30;

secondsPerYear = 60 * 60 * 24 * 30 * 12;

secondsRemaining = totalTimeInSeconds;

years = Math.floor(secondsRemaining / secondsPerYear);

secondsRemaining = secondsRemaining % secondsPerYear;

months = Math.floor(secondsRemaining / secondsPerMonth);

secondsRemaining = secondsRemaining % secondsPerMonth ;

days = Math.floor(secondsRemaining / secondsPerDay);

secondsRemaining = secondsRemaining % secondsPerDay ;

hours = Math.floor(secondsRemaining / secondsPerHour);

secondsRemaining = secondsRemaining % secondsPerHour;

minutes = Math.floor(secondsRemaining / secondsPerMinute);

secondsRemaining = secondsRemaining % secondsPerMinute ;

seconds = secondsRemaining;

txt = "";

txt += yearleadingZeros(years);

txt += leadingZeros(months);

txt += leadingZeros(days);

txt += leadingZeros(hours);

txt += leadingZeros(minutes);

txt += leadingZeros(seconds);

txt;

function yearleadingZeros(i){

x = "0" + Math.floor(i);

return x;

}

function leadingZeros(i){

x = "0" + Math.floor(i);

x = ":" + x.substr(x.length-2, 2);

return x;

}

• | **Re: Year countdown timer expression problem** on Sep 7, 2018 at 2:13:52 am |

I just tired using your code above and keep getting the following error:

After Effects warning: Expression Disabled. Error at line 5 in property 'Source Text' of layer 1 ('TIMER') in comp 'timer'.

Expected: ).

I'm quite certain I'm less qualified than yourself in these things -- is this a quick fix? Any suggestions?

Thanks!

• | **Re: Year countdown timer expression problem** on Sep 7, 2018 at 6:16:18 am |

In the two lines that have **<** try substituting **<** and see if that fixes it.

Dan

• | **Re: Year countdown timer expression problem** on Sep 7, 2018 at 6:19:35 am |

That didn't come out right. The problem is that < gets converted to ampersand+lt; if you preview a message before you post it. So just find the places where that happened and switch back to <.

Dan