These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Getting only the month out of a date-field

hedrich
Registered: Nov 26 2008
Posts: 28

Hi,

is there a chance to get only the "month" out of a date field ?

Example: "21.10.2008" should be converted to "10" .

Kind Regards
Holger

My Product Information:
Acrobat Pro 9.0, Macintosh
try67
Expert
Registered: Oct 30 2008
Posts: 2399
If this is the exact way your field is formatted, there are probably several ways to get it.
Here's one:

a="21.10.2008";
myMonth = a.split(".")[1];

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

hedrich
Registered: Nov 26 2008
Posts: 28
Hi try67,

can you please tell me, where the script must be placed?

The example date "21.10.2008" is imported in the textfield; there were also 150 other imported datefields.

Kind Regards
Holger
gkaiseril
Expert
Registered: Feb 23 2006
Posts: 4308
You can use that script in the custom calculaiton script.

For more flexible programing you might change the date string into a JavaScript date time object and then you get different display formats and calculation vaues from that object.

var a = "21.10.2008"; // date string format is "dd.mm.yyyy"// convert date string into date objectvar oDate = util.scand("dd.mm.yyyy", a);// display various month formatsconsole.show();console.clear();// get month from date object with zero based month valuevar sMonth = oDate.getMonth() + 1;console.println("Month number: " +  sMonth);// get month from date objce with util.printd() method in various displays// month numbersMonth = util.printd("mm", oDate);console.println("Month number: " + sMonth);// short month textsMonth = util.printd("mmm", oDate);// long month textconsole.println("Short month: " + sMonth);sMonth = util.printd("mmmm", oDate);console.println("Long month: " + sMonth);

George Kaiser

hedrich
Registered: Nov 26 2008
Posts: 28
Hi gkaiserli,

thanks for your prompt answer. After using this script in the custom calculation section the result is always perfect (the console opens with the "month-options").

Is there a chance that the script should automaticly detect the right month (there are about 200 students with different birthdays ...) and put the selected month description ("10" or "09" or "02") into another textfield of my acrobat form?

Kind Regards
Holger