ADOBE AFTER EFFECTS: Forum Expressions Tutorials Creative Cloud

D.getDate() "st" "th" "rd" "nd"

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Scott McGee
D.getDate() "st" "th" "rd" "nd"
on Jul 14, 2017 at 8:00:42 am
Last Edited By Scott McGee on Jul 14, 2017 at 8:13:03 am

Other than the obvious which is add something like

I = D.getDate();
if (I == "14") = {I + "th"}

and incorporate it in the below. Is there an easier way to add "th" "nd" "rd" "st"?

month = new Array();
month[0] = "January";
month[1] = "February";
month[2] = "March";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "August";
month[8] = "September";
month[9] = "October";
month[10] = "November";
month[11] = "December";

D = new Date(Date(0));
"" + D.getDate() + " " + month[(D.getMonth())] + " " + D.getFullYear()

I'm probably being a bit thick, but thought I'd ask if anyone has any other quick solutions that to write and Array and if it ends in 1 put "st" etc.

Also whilst I'm playing around with this,

Is there an easy way to get something like this to work?

D = new Date(Date(0));
Day = (D.getDate());
Month = month[(D.getMonth())];

If (Day + Month == "July 31"){"" + month[(D.getMonth()+1)] + "1st")};
else
{""+ Month + " " + Day} ;

I have to export tomorrows date, but adding a plus one to the day is no problem, but if it's the last day of the month I get July 32 hahaha, but I need August 1


Return to posts index

Scott McGee
Re: D.getDate() "st" "th" "rd" "nd"
on Jul 14, 2017 at 3:43:38 pm

I'm an idiot, because I was put them in separate brackets that was my issue

if (Day == "31" && Month == "July") {"August 1"}

Then the below I set up to do "st" "nd" "rd" and "th"

Unless someone has an easier solution, I'm fine with this way of doing it.

month = new Array();
month[0] = "January";
month[1] = "February";
month[2] = "March";
month[3] = "April";
month[4] = "May";
month[5] = "June";
month[6] = "July";
month[7] = "August";
month[8] = "September";
month[9] = "October";
month[10] = "November";
month[11] = "December";

D = new Date(Date(0));
Day = (D.getDate());
Month = month[(D.getMonth())];

if (Day == "2" | Day == "22") {""+ Month + " " + Day + "nd"}
else if (Day == "1" | Day == "21" | Day == "31") {""+ Month + " " + Day + "st"}
else if (Day == "3" | Day == "23") {""+ Month + " " + Day + "rd"}
else
{""+ Month + " " + Day + "th"};


Return to posts index

Scott McGee
Re: D.getDate() "st" "th" "rd" "nd"
on Jul 14, 2017 at 5:39:37 pm

And as tired as I was when I originally posted this I realised.

Using this could help hahaha

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

Not gonna lie, have no idea how it works, other than getting the time of + 1 day, 24 hours, 60 minutes, 60 seconds, 1000 milliseconds.

But this works to pick the next day and if that happens to be a new month. It changes the month aswell.

Hurrah.


Return to posts index

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