Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

javascript to show date field in the format as below

Engaged ,
Jul 19, 2016 Jul 19, 2016

I am making a form in which client need the date to be shown in the format as below

Like if he puts  date  13/05/2015 then it should show  as  May 13th, 2016  (plz note there should be "th" after 13)

                                  19/07/2016  should show as July 19th, 2016     ("th" after 19 should be there)

Thanking you

TOPICS
Acrobat SDK and JavaScript , Windows
1.4K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Jul 20, 2016 Jul 20, 2016

This way of enumerating numbers is known as "Ordinal". There are many was to script this. What works for web JavaScript can easily work with little modification in Acrobat forms. This type of date format is usually used in legal forms.

You should be able to search the forums for "legal date" or "ordinal" and find the post.

I found a JavaScript function that can take as input a number and returns the number with the ordinal suffix. This allows you to create any number of date formats.

This function

...
Translate
Community Expert ,
Jul 20, 2016 Jul 20, 2016

There's no built-in option to do that (the problem is the "-th" suffix). You will need to write your own custom Format script to achieve it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 20, 2016 Jul 20, 2016

could you provide me with the javascript .

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 20, 2016 Jul 20, 2016

This way of enumerating numbers is known as "Ordinal". There are many was to script this. What works for web JavaScript can easily work with little modification in Acrobat forms. This type of date format is usually used in legal forms.

You should be able to search the forums for "legal date" or "ordinal" and find the post.

I found a JavaScript function that can take as input a number and returns the number with the ordinal suffix. This allows you to create any number of date formats.

This function is not limited to just dates bat can be used to add the ordinal suffix to any number.

The function:

function ordinal_suffix_of(I)I

{

    var j = i % 10, // 10's remainder

        k = i % 100, //100's remainder

        cSuffix = "th"; // default suffix result

    if (j == 1 && k != 11) {

  // not 11;

        cSuffix = "st";

    }

    if (j == 2 && k != 12) {

  // not 12;

        cSuffix = "nd";

    }

    if (j == 3 && k != 13) {

  // not 13;

        cSuffix = "rd";

    }

    return i + cSuffix;

} // end ordial_suffix function;

I would place this code in the document level script location and then call it as needed in the various fields.

I would enter the date in different field that would not print and then have the formatted date in a different field. You should know how to split the inputted date string into the month, date, and year parts and then rearrange them as needed.

You can test the code using the Acrobat JavaScript console:

function ordinal_suffix_of(i)
{
    var j = i % 10, // 10's remainder
        k = i % 100, //100's remainder
        cSuffix = "th"; // default suffix result
    if (j == 1 && k != 11) {
  // not 11;
        cSuffix = "st";
    }
    if (j == 2 && k != 12) {
  // not 12;
        cSuffix = "nd";
    }
    if (j == 3 && k != 13) {
  // not 13;
        cSuffix = "rd";
    }
    return i + cSuffix;
} // end ordial_suffix function;

function MyDateFormat(cFormat, cDate)
{
var oDate = util.scand(cFormat, cDate);
if(oDate == null)
{app.alert("Invalid date provided", 1, 0);
}
else
{
return util.printd("mmmm", oDate) +" " + ordinal_suffix_of(oDate.getDate()) + ", " + util.printd("yyyy", oDate);
}
}

var dateInput = "13/05/2015"; // inputted date value;
var cFormattedDate = MyDateFormat("d/mm/yyyy", dateInput); // formatted string for date;
console.println(cFormattedDate);
dateInput = "23/5/2015";
console.println(MyDateFormat("d/mm/yyyy", dateInput));
dateInput = "19/07/2015";
console.println(MyDateFormat("d/mm/yyyy", dateInput));
dateInput = "9/07/2015";
console.println(MyDateFormat("d/mm/yyyy", dateInput));

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 22, 2016 Jul 22, 2016

Sir,

I am not able to make this work for my form,,, plz explain where i am going wrong..

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 22, 2016 Jul 22, 2016
LATEST

Your posts do not show me what you are doing.

The following link connects to working form:

OrdinalSuffix

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines