Copy link to clipboard
Copied
I created a table filled with some date fields, starting, let's say, from day=0 to day=n
[using for each value from day=1 to day=n the script:
var theDate = util.scand("dd/mm/yyyy", this.getField("Day 0").value); theDate.setDate(theDate.getDate()+n);
event.value = util.printd("dd/mm/yyyy", theDate);]
Now, I want to create a new text field (as table title) showing, for instance, "January 2023" if both day=0 and day=n are in the same month (for example from Jan-12 to Jan-25) BUT it must show "January-February 2023" if day=0 and day=n are in two months in sequence (for example from Jan-22 to Feb-4) OR "December 2023-January 2024" if the date span is for example from Dec-22 to Jan-4.
Thank you in advance
Copy link to clipboard
Copied
Use "mmmm" to get month in text, something like this:
util.printd("mmmm", theDate)
Copy link to clipboard
Copied
You can use this code to do it:
var s1 = this.getField("Day 0").valueAsString;
var s2 = this.getField("Day 1").valueAsString;
if (s1=="" || s2=="") event.value = "";
else {
var d1 = util.scand("dd/mm/yyyy", s1);
var d2 = util.scand("dd/mm/yyyy", s2);
if (d1.getMonth()==d2.getMonth() && d1.getFullYear()==d2.getFullYear()) {
event.value = util.printd("mmmm yyyy", d1);
} else {
if (d1.getFullYear()==d2.getFullYear()) {
event.value = util.printd("mmmm", d1) + "-" + util.printd("mmmm", d2) + " " + util.printd("yyyy", d1);
} else {
event.value = util.printd("mmmm yyyy", d1) + "-" + util.printd("mmmm yyyy", d2);
}
}
}
Copy link to clipboard
Copied
The script works very fine, thank you so much! It shows month names in italian, as set in my Mac OS.
I wonder if it would be possible to get month names in all capital letters (as "GENNAIO" instead of "Gennaio").
Thank you again for your precious help!
Copy link to clipboard
Copied
Sure, just change these parts of the code:
util.printd("mmmm", d1)
To:
util.printd("mmmm", d1).toUpperCase()
Copy link to clipboard
Copied
Done. Thank you again.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now