Skip to main content
Participating Frequently
June 15, 2016
Question

I am trying to write a legal script in JAVA DC. The script i have currently will only put today's date and will not allow me to input any other date. I would like to be place any date in the field. Can anyone assist me? I am using this scritp:

  • June 15, 2016
  • 4 replies
  • 800 views

I am trying to write a legal script in JAVA DC.  The script i have currently will only put today's date and will not allow me to input any other date.  I would like to be place any date in the field.  Can anyone assist me?  I am using this scritp: 

var oDate=new Date();

var sDay+util.printd("d",oDate);

varaSuffix=["","st","nd","rd","th","th","th","th","th","th"."th","th","th","th","th","th","th","th","th","th","th","st"];

var sDD=sDay+aSuffix[+sDay]

event.value=(sDD+util.printd("DAY OFmmmm,yyyy", oDate)).to uppercase();

This topic has been closed for replies.

4 replies

Inspiring
June 15, 2016

What is a "legal" script. A script is an series of statements that either works or does not work.  If by "legal" you mean has valid statements and works, then you script is no legal.

Can you simply explain what you are trying to accomplish.

It looks like you want a script that formats a date into the format of legal date string. This format is the ordinal date number " day of " long month name, 4 digit year.

Have you searched this forum for "Legal Date"?

Inspiring
June 15, 2016

Also, tell us where you placed that script and exactly what you want to achieve.

Participating Frequently
June 15, 2016

The goal I am trying to achieve is to produce the following example legal date:  9TH DAY OF SEPTEMBER, 2016  .  I have used the following script:

var oDate = new Date();

var sDay = util.printd("d", oDate);

var aSuffix = ["", "st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "th", "st", "nd", "rd", "th", "th", "th", "th", "th", "th", "th", "st"];

var sDD = sDay + aSuffix[+sDay];

event.value = (sDD + util.printd(" DAY OF mmmm, yyyy", oDate)).toUpperCase();

This script does provide today's legal date; however, it will not allow me to place any other date, which I would like to place whatever date I need to use.  I hope this helps.

Inspiring
June 15, 2016

That script can be used as a custom calculation script to automatically set its value to the current date. You haven't said how you want the user to be able to enter the date to use or when you want the script to run. If you can explain in more detail what you want the user experience to be, that would be helpful.

For example: "I want the user to be able to enter a date in one field using the format mm/dd/yyyy and have this date automatically appear in another field formatted as the legal date."

Inspiring
June 15, 2016

If that's your current script, it has many errors, so it can't work. If that not exactly what you're currently using, then post again and include your current script.

Karl Heinz  Kremer
Community Expert
Community Expert
June 15, 2016

This actually has nothing to do with Acrobat's implementation of JavaScript. The "Date" object is part of the Javascript core language.

Please review the information about the Date object e.g. here: Date - JavaScript | MDN

In the samples section of that page you will find a number of different ways to initialize a Date object (this is quoted directly from the MDM page):

var today = new Date();
var birthday = new Date('December 17, 1995 03:24:00');
var birthday = new Date('1995-12-17T03:24:00');
var birthday = new Date(1995, 11, 17);
var birthday = new Date(1995, 11, 17, 3, 24, 0);

You are using the first type, which always initializes the Date object with the current date and time - that's why you are getting today's date. To use any other date, you would have to pass in one or more parameters with information about which date and time you want to use