6 Replies Latest reply on Dec 15, 2010 12:05 AM by George_Johnson

    help with a script for date

    sicilianmissy65 Level 1

      I am creating a form and the only options adobe (pro 9) gives me is the month/date/year fromat but it does not fill in the "/", so the person will have to put them in for the date to be accepted.


      I was hoping to find a way to maybe run the script so if one was to enter '121010" it will convert to 12/10/2010...

      Can anyone help me with this?


      Thank you!

        • 1. Re: help with a script for date
          gkaiseril MVP & Adobe Community Professional

          That is the way the system works. You can do all the coding you can do the custom keystroke needed for the 6 character string with and without the separators, the custom format, and do not forget you will need to validate the date to make sure it is a valid date. Part of the Millennium issue was proper date validation in February, besides the 2 digit year. You may also have users try to enter dates as dd/mm/yy or yy/mm/dd which for some dates are valid.


          A simple format script could be:


          event.value = event.value.substr(0,2) + "/" + event.value.substr(2,2) + '/' + event.value.substr(4,2);

          It does not allow for null entries, separators, and does no date validation.

          • 2. Re: help with a script for date
            sicilianmissy65 Level 1

            Thank you!  I have to laugh at myself... you are so very helpful, but your answers are still a bit 'greek' to me.  I am truly a novice and just learning the 'lingo' and functionalities... so I have to really concentrate on what your answers are (and others) in meaning for my procedural steps...

            I do appreciate your help!!


            I am assuming I should just copy your script into the "format tab' of the properties of the date field after selecting custom???


            or are you saying I must do it in the 'validate' tab when you speak of validation?


            I am so sorry to be so naive (stupid in fact at this point) on this stuff, but we all have to start somewhere...

            Hope to hear back from you on this...


            thank you again!

            • 3. Re: help with a script for date
              sicilianmissy65 Level 1

              Okay, my assumption is obviously wrong!!  I am sitting here laughing at myself...

              I copied and pasted the formula you gave me into the custom field of 'format' tab... but it is giving me a pop up saying "invalid date and time; please ensure that date/time exists; Field (Date) should match format NaN"


              I don't need time in there, just date... and I am not sure what the script you gave me means or how to write them?  Could you maybe help me alter it so if i input '121010' it will auto fill 12/10/2010?  I would greatly appreciate it...


              I am trying to read my book and do my tutorials and a class on all this, but it really takes a great deal of time and I am caring for a mother with MS in between trying to teach myself this and make a little money at making forms.


              Thank you again!!


              • 4. Re: help with a script for date
                gkaiseril MVP & Adobe Community Professional

                It is just for the custom format.


                The script does not cover keystroke input or validation due to the complexity (RegExp coding) and amount of the script needed to do those task.

                • 5. Re: help with a script for date
                  sicilianmissy65 Level 1

                  okay, i have been playing with what you told me to do and I just copied your script (because I do not know how to wri

                  te these -or even interpret them yet) into the custom field... and in the validation script ( not sure if that is correct) then in format tab I selected mm/dd/yyyy


                  so when I type in 121010 it comes out 1/1/10...

                  What is wrong?

                  • 6. Re: help with a script for date
                    George_Johnson MVP & Adobe Community Professional

                    The problem with this is it's not really that simple. George tried to explain that a bit, and the script he posted was just a part of a possible solution.


                    It might help to step back a bit and start from the beginning. The first thing you need to do is settle on the design. This includes the following:


                    What characters should the user be allowed to enter? Is it just six digits, or should they be allowed to enter backslash or dashes to indicate year/month/day separators? What should happen, exactly, if fewer than six digits are entered? What should the format be: YYMMDD, MMDDYY, or something else? Do you want to add day/month/year separators (if any) to the underlying field value, or just to what gets displayed in the field when the value is committed? I probably missed some, but the point is you need to be very specific and complete in determining how you want the field to behave.


                    When you select one of the built-in date formats, Acrobat sets up calls to built-in routine for the Keystroke and Format events. The Keystroke event calls some code that doesn't limit what characters can be entered, which a Keystroke script commonly would do (and probably what you should do), but does validate that the characters entered look something like the selected format (e.g., mm/dd/yyyy) and verifies that the value represents a valid date. This code is rather tolerant of separators. For example, it will accept a comination of a decimal point, backslash, space, and dash as separators. The code for all of this is rather complex.


                    If it passes the checks in the Keystroke scripts, the Format code gets executed. This code again checks for a vailid date and adds separators based on the selected format. For example, an field value of "12.14 2010" will be accepted as representing a valid date and it will display in the field as "12/14/10", if a format of "m/d/yy" is selected. Note that this scheme depends on the user using some type of separator, even though it allows the user to be inconsitent, as in the example I just gave.


                    In short, it can get complicated, and the solution depends on the details. Since the details dictate the code, you will need to supply all of the details by answering the questions above before anyone can suggest code that you can use.