Copy link to clipboard
Copied
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
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
...Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
could you provide me with the javascript .
Copy link to clipboard
Copied
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));
Copy link to clipboard
Copied
Sir,
I am not able to make this work for my form,,, plz explain where i am going wrong..
Copy link to clipboard
Copied
Your posts do not show me what you are doing.
The following link connects to working form:
Find more inspiration, events, and resources on the new Adobe Community
Explore Now