Creative Communities of the World Forums

The peer to peer support community for media production professionals.

Activity Forums Adobe After Effects Expressions Date given + 7 or something else

  • Date given + 7 or something else

    Posted by Scott Mcgee on August 8, 2017 at 9:11 pm

    I’m given an upload date in a text file.

    example 2017-08-08

    I need an expression that will take this static date and add 7.

    So that it works out

    current date might be 2017-08-10;

    date1 = 20170808
    date2 = 20170815

    The problem is, I can’t simply just put 20170808 + 7, well I could in this case, but not 20170831, because this will go above an actual date.

    D = new Date(new Date(Date(0)).getTime()+1*24*60*60*1000);
    D.getDate();

    I can’t use this expression for date2 because I need it to be + 7 from date1, otherwise I can’t use my try catch expression

    So the final result would be. Someone uploads an image that gets replaced, no script. Just a simple find and replace in a folder with an updated .txt document (Containing a name, location and upload date). After 7 days, if this file isn’t replace. It goes back to the default image below.

    My expression currently works fine, but the guy who’s providing the data, says it’s too much hassle to set his system to include an expiry date rather than an upload date. If I got an expiry date, I could just use an expression if(expiry > date). I wouldn’t be having to ask for any help.

    Can anyone think of a way to take the date I’ve been given and create a new date +7 based off that date. I’ve got the expression nailed down for the rest, just need this part.

    Scott Mcgee replied 9 years ago 2 Members · 5 Replies
  • 5 Replies
  • Dan Ebberts

    August 8, 2017 at 9:55 pm

    Couldn’t you just create your date object, convert it to milliseconds with D.getTime(), add 7 days worth of milliseconds, and create a new Date object from that?

    Dan

  • Scott Mcgee

    August 8, 2017 at 10:12 pm

    At the risk of sounding stupid

    Is the date object when you write it

    new Date(Aug 08 2017)?

    I never written an expression like that before, but if that’s what you mean.

    If so… I’m stupid for not thinking that simply and secondly Could you write that using yyyymmdd, otherwise I’ll need to get the pho document changed.

    And thanks for the suggestion. I’ve spent ages searching for datestring, convert number to date etc. I did not think Date object haha

  • Dan Ebberts

    August 8, 2017 at 10:40 pm

    Try this:

    var D = new Date(“August 8, 2017”);
    var ms = D.getTime() + 7*24*3600*1000;
    var D2 = new Date(ms);
    alert(D2.getDate()); // should be 15

    Dan

  • Scott Mcgee

    August 9, 2017 at 8:40 am

    I jazzed it up a little to compensate for single and double numbers in Days and Months.

    var D = new Date(“31 September 2017”);
    var ms = D.getTime() + 7*24*3600*1000;
    var D2 = new Date(ms);
    mo = “” + (D2.getMonth()+1)
    dy = “” + D2.getDate();
    yr = D2.getFullYear();

    if (dy.length < 2) dy = “0” + dy;
    if (mo.length < 2) mo = “0” + mo
    yr + mo + dy

    But that worked a treat. Cheers for that Dan.

  • Scott Mcgee

    August 9, 2017 at 12:34 pm

    Apologies Dan, I’ve just made a mountain out of a mole hill and lightbulb has finally turned on…I didn’t realise what you had given was a simple as it was. I thought I was going to have to do more with it.

    var D = new Date(“31 September 2017”);
    var ms = D.getTime() + 7*24*3600*1000;
    var D2 = new Date(ms);

    var curDate = new Date(Date(0));

    if(curDate < D2) “Correct” else “Wrong”

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