Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions After Effects Count Up Expression

  • After Effects Count Up Expression

    Posted by Shaun Pimley on April 7, 2016 at 2:07 pm

    Hi everybody and thank you in advance for looking into my question.

    I’ve just started to look into the world of count up expressions and am wondering if anybody can help me.

    I’m looking to create a count up expression which basically counts up to a year. The format I’m looking to have is months:days:hours and starting at 00:00:00 and ending at 12:31:23 I’d like it take ten minutes to reach the year mark.

    I’d really appreciate any help.

    Thank you!
    Shaun

    Shaun Pimley replied 10 years, 5 months ago 2 Members · 2 Replies
  • 2 Replies
  • Kalleheikki Kannisto

    April 9, 2016 at 12:08 pm

    It would go like this.

    (The count-up would start from 01:01:00, since there is no such thing as month 0 or day 0.)

    daysInMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; // array for number days in a given month
    hoursInYear = 365*24-1;// minus one hour so that countdown stops one hour before full year
    duration = 600; // time the countdown animation takes, in seconds
    hoursPerFrame = hoursInYear/duration; // one frame of animation represents this many hours

    animTime = Math.min(duration, time-inPoint); // stop countdown when duration reached

    hoursElapsed = Math.floor((animTime)*hoursPerFrame); // how many hours we are at

    daysElapsed =Math.floor(hoursElapsed/24); // how many full days is that
    hoursElapsed = hoursElapsed-24*daysElapsed; // subtract full days from hours

    // loop through each month, adding any full months and subtracting that number of days until days run out
    monthsElapsed = 0;
    i=0;
    while(daysElapsed>=daysInMonth[i]){
    monthsElapsed++;
    daysElapsed -= daysInMonth[i];
    i++
    }

    months = (monthsElapsed+1).toString(); // first month is 1, not 0
    days = (daysElapsed+1).toString(); // first day is 1, not 0
    hours = hoursElapsed.toString();

    // ensure all values have two digits
    if(months.length==1){months = "0"+months}
    if(days.length==1){days = "0"+days}
    if(hours.length==1){hours = "0"+hours}

    // displayed result
    months + ":" + days + ":" + hours

    // you can format the results differently, such as
    // months + " months\n" + days + " days\n" + hours + " hours"

    Adjust daysInMonth and hoursInYear for leap years such as 2016.

  • Shaun Pimley

    April 11, 2016 at 11:27 am

    Thank you so much! Amazing!

We use anonymous cookies to give you the best experience we can.
Our Privacy policy | GDPR Policy