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

Date format in a combined string

Community Beginner ,
May 23, 2018 May 23, 2018

Hello,

I am using Adobe Acrobat XI Pro.  I have created a Custom Calculation Script to combine the fields "Date" and "CountyDD" into a third field called "CountyDateCombo."  The "CountyDD" field is a dropdown allowing the end user to select counties from a list.  The Custom Calculation Script in the "CountyDateCombo" field is as follows:

// Get the field values, as strings
var s1 = getField("CountyDD").valueAsString;
var s2 = getField("Date").valueAsString;

// Combine values, separated by a space
event.value = "In " + s1 + " County, on " + s2 + ".";

The date format I need for the "Date" field is mm-dd-yyyy (e.g. 05-20-2018), however, the date format I need for the "CountyDateCombo" field is mmmm d, yyyy (e.g. May 20, 2018).  I am combining the two fields so the final combined field would read e.g. "In Hennepin County, on May 20, 2018."  I have not been able to figure out how to change the date format in the "CountyDateCombo" field and was hoping someone out there can give me so assistance.

Thank you in advance

Steve

TOPICS
PDF forms
4.0K
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
1 ACCEPTED SOLUTION
LEGEND ,
May 23, 2018 May 23, 2018

A line was out of the correct order.

// Get the field values, as strings;

var s1 = getField("CountyDD").valueAsString;

var s2 = getField("Date").valueAsString;

// reformat the date string;

var oS2 = util.scand("mm-dd-yyyy", s2);

var s3 = util.printd("mmmm d, yyyy", oS2)

// Combine values, separated by a space

event.value = "In " + s1 + " County, on " + s3 + ".";

View solution in original post

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 ,
May 23, 2018 May 23, 2018

Acrobat JavaScript includes concatenation either by use of the "concat" method or the "+" operator when used with a string.  You will also need to convert you "Date" field value to the "mmm d, yyyy" format.

// Get the field values, as strings;

var s1 = getField("CountyDD").valueAsString;

var s2 = getField("Date").valueAsString;

var s3 = util.printd("mmmm d, yyyy", oS2)

// reformat the date string;

var oS2 = util.scand("mm-dd-yyyy", s2);

// Combine values, separated by a space

event.value = "In " + s1 + " County, on " + s3 + ".";

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
Community Beginner ,
May 23, 2018 May 23, 2018

Hi gkaiseril,

Thank you for your response.  I copied your code into my Custom Calculation script and changed the "Date" field to "mmmm d, yyyy" format as suggested and nothing happened.  The only thing that did change was the format for the "Date" field, which changed to "mmmm d, yyyy" format.  I am wondering if something is missing because nothing gets updated even if I change the county from the dropdown list.

Also is it possible to keep the "Date" field format as mm-dd-yyyy instead of changing it to mmmm d, yyyy?

Steve

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 ,
May 23, 2018 May 23, 2018

A line was out of the correct order.

// Get the field values, as strings;

var s1 = getField("CountyDD").valueAsString;

var s2 = getField("Date").valueAsString;

// reformat the date string;

var oS2 = util.scand("mm-dd-yyyy", s2);

var s3 = util.printd("mmmm d, yyyy", oS2)

// Combine values, separated by a space

event.value = "In " + s1 + " County, on " + s3 + ".";

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
Community Beginner ,
May 23, 2018 May 23, 2018
LATEST

Thank you very much.  Works perfectly!!

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