Page 1 of 1

date?

Posted: May 19th, 2006, 12:14 pm
by lloydalvarez
is there a way to get the current date using expressions?

Posted: May 19th, 2006, 12:48 pm
by Dan Ebberts
I don't think so Lloyd. You can use the Date methods to format and manipulate a date (that you supply), but you can't get at the system date/time.

Dan

Posted: May 19th, 2006, 5:23 pm
by nab
hello,
could you (Dan) briefly explain how the Date(number) method works in expressions ?
if I write this expression for source text

Code: Select all

Date(0);
I get the current date and time and it updates as the comp time augments.
if I replace '0' by any other number (10000000 for example), it doesn't seem to change anything.

simply a curiosity...thanks.

Posted: May 19th, 2006, 6:36 pm
by Dan Ebberts
Wow - I didn't know that would work (sorry Lloyd). I've got to run, but I'll play around with this later. Thanks!

Dan

Posted: May 19th, 2006, 10:38 pm
by Dan Ebberts
This is most bizarre. According to my JavaScript reference, there is a Date() function (which returns a string) and a Date() constructor that returns a date object (with which you can use the Date() methods, like getDay(), getFullYear(), etc) Using either of these with no parameters is supposed to get you the current (system) date and time. But if you try to use the function:

myDate = Date();

or the constructor:

myDate = new Date();

You will get this error:

"Can't use Date() in After Effects to get current date. You can use the constructor with arguments."

Which implies that AE does not want you to get the system date/time. There's probably a good reason for that, because I would think you'd run into issues with cached frames not matching up with unrendered frames. My guess is that Date(0) as a function call somehow snuck under the radar.

The time part doesn't appear to be very useful because of the discontinuities. But you could get the date (which should be OK as long as you don't cross midnight) like this:

parts = Date(0).split(" ");
parts[0] + " " + parts[1] + " " + parts[2] + " " + parts[3]

Note that you'd use the string method split() and not any of the Date() methods because Date() as a function returns a string.

So, I think you may have discovered an unintentional feature. :-)

Dan

Posted: May 19th, 2006, 11:44 pm
by lloydalvarez
aha! i was going to tell you about the weird error that AE gives, but i figured you'd see it yourself. thanks for figuring it out, i am sure it would have taken me much longer!

lloyd

Posted: May 20th, 2006, 10:56 am
by nab
I also got the same error... that's why I tried to specify an argument (an integer in my case).
I've made my own experiments too ... just for fun
I put this sourceText expression that mainly consists in a while loop and call the Date() function before/after the loop to get the 'running time'.

Code: Select all

i = 0; imax = 8000000;
dateStart = Date(0);
while (i < imax) i++;
dateEnd = Date(1);
dateStart +"\r" + dateEnd;
kind of "benchmark expression" :)

now to format it...

Posted: June 21st, 2006, 5:24 am
by ScottG
so we can get the current date (which answers part of my question which i just posted on the cow).

but then... how to format it? i want my date to appear in all caps, and there seems to be no way to do this.

would anyone happen to have solution? i'm stumped.

once i can format it according to my every whim, it makes the task of creating daily slates so much easier. :)

Re: now to format it...

Posted: June 21st, 2006, 10:43 am
by lloydalvarez
ScottG wrote: but then... how to format it? i want my date to appear in all caps, and there seems to be no way to do this.

would anyone happen to have solution? i'm stumped.

Code: Select all

parts = Date(0).toUpperCase().split(" ");
parts[0] + " " + parts[1] + " " + parts[2] + " " + parts[3]