Skip to main content
jrp0742
Inspiring
January 13, 2018
Answered

format a PDF form date as example " 12TH DAY OF JANUARY, 2018 "

  • January 13, 2018
  • 10 replies
  • 7104 views

How can I format a PDF form date field as example  " 12TH DAY OF JANUARY, 2018 " (Acrobat 2017 PRO)

This topic has been closed for replies.
Correct answer jrp0742

Thanks... I tried and it DID work GREAT  BUT now I added it to my PDF,   and it does not work ( I even tried it on a "BLANK pdf" )?   What have I missed.  ??

"// for the "Format" tab enter the following "Custom  Format Script", do not use the "Date" format option:

if(event.value != "") event.value = legalDate(util.scand("dd-mmm=yyyy", event.value)).toUpperCase();

"

10 replies

jrp0742
jrp0742Author
Inspiring
January 17, 2018

FIXED .. you were correct both the "getOrdinalNum" and "legalDate" when added resolved the issue.. My nubee THANKS! for you help..

jrp0742
jrp0742Author
Inspiring
January 17, 2018

I currently have NO form that works.. all fail

jrp0742
jrp0742Author
Inspiring
January 17, 2018

It is a TEST form that fails

jrp0742
jrp0742Author
Inspiring
January 17, 2018

I can send my failing one cell form..

jrp0742
jrp0742Author
Inspiring
January 17, 2018

yes ..

"

ReferenceError: legalDate is not defined

3:Field:Format

"

Inspiring
January 17, 2018

That is the name of one of the document level functions:

function legalDate(oDate) {

// return ordinal date string form passed date object;

return getOrdinalNum(oDate.getDate()) + " day of " + util.printd("mmmm", oDate) + " " + oDate.getFullYear();

}

If you are missing that function then you are certainly also missing the "getOrdinalNum" function.

You will need to add these functions as document level functions or include them in your calculation field.

jrp0742
jrp0742Author
Inspiring
January 17, 2018

The issue exists in IE and Acrobat pro

Inspiring
January 17, 2018

If the sample form works, then there must be some difference in the scripts in the sample form and your form. Since you have access to the sample form you can see what is missing.

Without access to your form I can only guess.

jrp0742
jrp0742Author
Inspiring
January 17, 2018

yes.. no error from "custom validation script " .. except when in testing when  I did intentionally enter an invalid date..

Inspiring
January 17, 2018

Did you open the JavaScript console by using the <Ctrl> + "J" key combination?

Inspiring
January 13, 2018

You need to find the ordinal suffix for the day of the month and then create the formatted string;

You have not explained how the date will be entered into the form.

I would create the following document level functions:

function getOrdinalNum(n) {

// append ordinal suffix to n value;

  return n + (n > 0 ? ['th', 'st', 'nd', 'rd'][(n > 3 && n < 21) || n % 10 > 3 ? 0 : n % 10] : '');

}

function legalDate(oDate) {

// return ordinal date string form passed date object;

return getOrdinalNum(oDate.getDate()) + " day of " + util.printd("mmmm", oDate) + " " + oDate.getFullYear();

}

For auto filling a date field, create the following document level script:

// fill in field AutoLegalDate on open of PDF;

this.getField("autoLegalDate").value = legalDate(new Date()).toUpperCase();;

For entering a date value into a form field with a date format of "dd-mmm-yyyy" enter the following scripts:

// custom validation script on the "Validation tab;

if(util.scand("dd-mmm-yyyy", event.value) == null) {

app.alert("Enter valid date as dd-mmm-yyyy", 1, 0);

event.rc = false;

}

// for the "Format" tab enter the following "Custom  Format Script", do not use the "Date" format option:

if(event.value != "") event.value = legalDate(util.scand("dd-mmm=yyyy", event.value)).toUpperCase();

Link to ordinalSuffix.pdf, a working example, does not force all caps.

jrp0742
jrp0742AuthorCorrect answer
Inspiring
January 17, 2018

Thanks... I tried and it DID work GREAT  BUT now I added it to my PDF,   and it does not work ( I even tried it on a "BLANK pdf" )?   What have I missed.  ??

"// for the "Format" tab enter the following "Custom  Format Script", do not use the "Date" format option:

if(event.value != "") event.value = legalDate(util.scand("dd-mmm=yyyy", event.value)).toUpperCase();

"

Inspiring
January 17, 2018

Did you get any error message pop-up or in the JavaScript console?

There are 2 document level functions that need to be added to the PDF.

JR Boulay
Community Expert
Community Expert
January 13, 2018

You should use a custom format, like this one:

dd\t\h \d\a\y \o\f mmmm, yyyy

Text field properties : Format : Date :

Acrobate du PDF, InDesigner et Photoshopographe
try67
Community Expert
Community Expert
January 13, 2018

That won't work because it's not always "th". For example, if it's the first day of the month it needs to be "1st", not "1th"...

JR Boulay
Community Expert
Community Expert
January 13, 2018

That won't work because it's not always "th". For example, if it's the first day of the month it needs to be "1st", not "1th"...

Yes, yes, yes.

Sorry, I did not pay attention because in French we do not have this problem, it's always the same.

Acrobate du PDF, InDesigner et Photoshopographe
try67
Community Expert
Community Expert
January 13, 2018

You would need to use a custom format script that will convert the user's input into this string. The trickier part is the ordinal suffix after the date ("-st", "-nd", "-rd", "-th").