ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

Date given + 7 or something else

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Scott McGee
Date given + 7 or something else
on Aug 8, 2017 at 9:11:03 pm
Last Edited By Scott McGee on Aug 8, 2017 at 9:13:16 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.


Return to posts index

Dan Ebberts
Re: Date given + 7 or something else
on Aug 8, 2017 at 9:55:49 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



Return to posts index

Scott McGee
Re: Date given + 7 or something else
on Aug 8, 2017 at 10:12:58 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


Return to posts index


Dan Ebberts
Re: Date given + 7 or something else
on Aug 8, 2017 at 10:40:15 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



Return to posts index

Scott McGee
Re: Date given + 7 or something else
on Aug 9, 2017 at 8:40:09 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.


Return to posts index

Scott McGee
Re: Date given + 7 or something else
on Aug 9, 2017 at 12:34:09 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"


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]