2 Replies Latest reply on Jun 4, 2015 9:46 AM by gkaiseril

    How to get date in a text field in dd-mmm-yyyy format in adobe acrobat?

    Alex Doubts Level 1

      How to get date in a text field in dd-mmm-yyyy format in adobe acrobat?

       

      I am able to get the current date in dd-mmm-yyyy fromat. But not so in the text field.

      var k=util.printd("dd-mmm-yyyy", new Date()); //12-Jun-2015

       

      But below code is not working

      var k=util.printd("dd-mmm-yyyy",getField("txtDate").value;

       

      Please update with a solution at the earliest.

        • 1. Re: How to get date in a text field in dd-mmm-yyyy format in adobe acrobat?
          try67 MVP & Adobe Community Professional

          First of all, you're missing the closing parenthesis in your code.

          Also, the second parameter of the printd method needs to be a Date object. The value of a field is usually a string, so it's not clear what you're trying to do, really. What is the value of that field? A date in a different format? Something else?

          • 2. Re: How to get date in a text field in dd-mmm-yyyy format in adobe acrobat?
            gkaiseril MVP & Adobe Community Professional

            When I try your code in the JavaScript console, I get the following JavaScript console error:

             

            TypeError: Invalid argument type.

            Util.printd:1:Console undefined:Exec

            ===> Parameter oDate.

            undefined

             

            Which means one of the 2 required parameters for the util.printd method is an invalid data type. The format is a string but the 2nd parameter is an object not a string.

             

            You might want to look at the MDN JavaScript Reference and the Acrobat JS API Reference for more information about the new Date()util.printd() , and util.scand().

             

            The new Date():

             

            "If no arguments are provided, the constructor creates a JavaScript Date object for the current date and time according to system settings."

             

            new Date() creates a date object not a string or number value.

             

            util.printd() formats a date date object to a string value.

             

            util.scand() converts a string to a date object.

             

            To reformat a date string form one format to another one must first create a date object and then create the string with desired format from the date object.

             

            var cOldFormat = "dd/mm/yyyy"

            var cNewFormat = "dd-mmm-yyyy";

            var cDate = getField("txtDate").value;

            var oDate = util.scand(cOldFormat, cDate)

            var k=util.printd(cNewFormat, oDate);

             

            Date arithmetic

             

            There is a wealth of information in the reference material. It is not always easy to read but once one understands the information it is invaluable.