4 Replies Latest reply on Apr 4, 2011 9:12 AM by lahglc

    Date/Time field format not wysiwyg

    lahglc

      I have a date field in my form that I formatted as m/d/yyyy hh:mm.  I thought that because it formats that field in that way my script would get passed down that way however it is not.  I want to manipulate it so the value is in the format I want it to be....

       

      I enter this in the date/time field: April 1, 2011 1:40PM

      When I click out of the field and I see: 4/1/2011 13:40

       

      Then I have a script that uses this field to make the file name but because I have a comma in there it will not save, if I take the comma out it will save.  So the main question is how do I format my field to pass down the value that I am seeing not the value that I am typing in.  You will notice I have a replace in there but I can't account for the comma because it reads it as part of the syntax.

       

      // Get the field value

       

      var dtentered = getField("datetime").value;

       

      //replace any odd characters that will not allow the file to save

       

      var fdt = dtentered.replace(/[!@#$%^&*()+=|\:;"'<>?/{}]/g,"_");

       

      // Specify the folder

      var fldr = "/c/WO Completed/";

       

      // Determine the full name and path

      var fp = fldr +  fdt + ".pdf";

       

        • 1. Re: Date/Time field format not wysiwyg
          try67 MVP & Adobe Community Professional

          You need to escape it with a back-slash. Also, you need to escape all the

          other special characters.

          • 2. Re: Date/Time field format not wysiwyg
            lahglc Level 1

            Thanks for the response...I'm not sure that I understand what you mean back-slash...I went ahead and did this but now it is giving me an odd file name

             

            // Get the field value

            var dt = getField("datetime").value;

            var mydt = escape(dt);

             

            //replace any odd characters that will not allow the file to save

            var fdt = mydt.replace(/[!@#$%^&*()+=|\:;"'<>?/{}]/g,"_");

             

            // Specify the folder

            var fldr = "/c/WO Completed/";

             

            // Determine the full name and path

            var fp = fldr + fdt + ".pdf";

             

            -----------------------------

             

            Returns a file name as

            April_201_2C_202011_201_3A40PM.pdf

             

            I was looking more for

            4_1_2011_13_40.pdf

             

            or

             

            April_1_2011_1_40PM.pdf

            • 3. Re: Date/Time field format not wysiwyg
              George_Johnson MVP & Adobe Community Professional

              If you want to get the formatted data as it appears in the field, set up a document-level function:

               

              function getFormattedDate(sFieldname, cFormat) {
              
                  var sDate = getField(sFieldname).valueAsString;
                  var date = AFParseDateEx(sDate, cFormat);
              
                  if (!date) {
                      return "";
                  } else {
                      return util.printd(cFormat, date);
                  }
              }
              

               

              and call it like this:

               

              var dt = getFormattedDate("datetime", "m/d/yyyy HH:MM");
              
              
              • 4. Re: Date/Time field format not wysiwyg
                lahglc Level 1

                Thank you George and Try67.  This last date format function works like magic!