4 Replies Latest reply on Mar 27, 2015 6:10 AM by aftamath77

    How do i format a date from a user input?

    aftamath77

      I am writing Javascript for a dynamic stamp date field that requests a users input.

       

      var cEntry = "Enter Date:";

      var cTitle = "Item Numbers Date";

      if(event.source.forReal && (event.source.stampName == "#g6KmvX-x4BphyE7tMLhbdC"))

      {

      var cDate = app.response(cEntry, cTitle);

      event.value = cDate("mmm dd, yyyy",new Date());

      event.source.source.info.DocumentState = cDate

      }

       

      This code will not format the date in the style shown nor will it update the date on the stamp to the user input.  Any help?  Is there code for a date picker?

        • 1. Re: How do i format a date from a user input?
          gkaiseril MVP & Adobe Community Professional

          Have you tried to work out your script in the JavaScript console before entering Into the stamp?

           

          The code:

           

          cDate("mmm dd, yyyy",new Date());

           

          Looks like a function call for the function "cDate".

           

          Have you looked at the Acrobat JavaScript documentation for the util.printd method?

           

          If you are using user date input you might want to consider some validation of the imputed value for being a valid date. Once a stamp is placed you will not be able to edit it.

           

          Have you looked at other dynamic stamps to see how the dates get formatted?

          • 2. Re: How do i format a date from a user input?
            aftamath77 Level 1

            Yes, I have looked at other dynamics stamps that use a date, i have seen the util.printd method and I currently use that.  But I need the ability to back date if necessary.  All of the stamps and examples of dates I've seen are for current system dates, not user input dates.  I'm looking to see if there is code that will format a value held in a variable that is inputted by a user.

             

            I can simply use event.date = cDate, which will return any value that a user inputs, regardless if it's even a date.  I would like to fool proof the input field to only return a date.  That's also where my interest in a date picker comes from.

            • 3. Re: How do i format a date from a user input?
              gkaiseril MVP & Adobe Community Professional

              Have you looked at how to reformat date strings?

               

              You should study the scripts and think long about how and why it works. Unless one knows the order of the parts of at date one cannot process the string.

               

              if one has a date string of 011015 what is the date?

              January 10, 2015?

              October 1, 2015?

              October 15, 2001?

               

               


              • 4. Re: How do i format a date from a user input?
                aftamath77 Level 1

                Let's say i changed the variable cEntry input screen to read var cEntry = "Enter Date: (mm/dd/yyy)", in order to give the user a date format to follow.  And let's assume that the user does enter in a date in this format, however the date is entered, 1-5-15.  The preferred date format output is 2 digit month, 2 digit day, and 4 digit year, so I would want the date printed on the stamp to be 01-05-2015.  Will Javascript recognize the 1-5-15 to be January 5th, 2015 and can Javascript reformat it to be 01-05-2015 if I tell it "mm/dd/yyyy"?