7 Replies Latest reply on Oct 20, 2009 1:49 PM by evidal2

    date separate year, month and day

    evidal2 Level 1
      Hello everyone and thanks in advance, I'm new to this and the truth is not doing this.
      Well, I have a PDF with several pages which I designed and has been asking me in a complete date in the format dd / mm / yy and subsequent pages he asks me the same date of birth but in 3 separate fields, day , month and year. I want you when you enter the date the first copy and separate day month and year in others. I tried this but I get
      var array_datesol = datesol.split("/")
      var year = parseInt(array_datesol[2]);
      var month = parseInt(array_datesoll[1]);
      var day = parseInt(array_datesol[0]);
      this.getField('yearsol').value = year;
      this.getField('monthsol').value = month;
      this.getField('daysol').value = day;
      where is the initial field datesol date and year, month and day where they have to be separately
      thanks in advance
        • 1. Re: date separate year, month and day
          try67 MVP & Adobe Community Professional

          Sorry, but it's not clear what's the problem.

          Could you specify what it is that is going wrong with your script?

          • 2. Re: date separate year, month and day
            evidal2 Level 1
            Excuse me as I use the google translator and do not know if I make myself clear because my English level is low.

             

            I have an initial field where you must enter a date in the format dd / mm / yyyy, this field is called datesol, what I need is for the day, month and year of the field passing through three separate fields called yearsol, monthsol and daymonth

             

            A greeting and thanks
            • 3. Re: date separate year, month and day
              try67 MVP & Adobe Community Professional

              Yes, that part I got. But your script seems fine to me. What is NOT working

              with it?

              • 4. Re: date separate year, month and day
                gkaiseril MVP & Adobe Community Professional

                Have you looked at the Adobe Acrobat JavaScirpt documentation?

                 

                You can use JavaScript's date object and then use various methods to get the month, day, and year from that object.

                 

                // establish a data sting mm/dd/yyyy format
                var sMyDate = '29/02/2000'; // or get value of field
                // display string
                console.println('sMyDate: ' + sMyDate);
                // convert to JavaScript date object
                var oMyDate = util.scand('dd/mm/yyyy', sMyDate);

                // display date object
                console.println('oMyDate: ' + oMyDate);

                // use the date object to get the parts of the date
                // month - zero - based January =  0
                var sObjMonth = oMyDate.getMonth();
                // display JS getMonth
                console.println('sObjMonth: ' + sObjMonth);
                // date
                var sObjDate = oMyDate.getDate();
                // display JS getDate
                console.println('sObjDate: ' + sObjDate);
                // full year
                var sObjFullYear = oMyDate.getFullYear();
                // display JS getMonth
                console.println('sObjFullYear: ' + sObjFullYear);

                 

                // use util.printd() method
                // month
                var sUtilMonth = util.printd('m', oMyDate);
                console.println('sUtilMonth m: ' + sUtilMonth);
                sUtilMonth = util.printd('mm', oMyDate);
                console.println('sUtilMonth mm: ' + sUtilMonth);
                sUtilMonth = util.printd('mmm', oMyDate);
                console.println('sUtilMonth mmm: ' + sUtilMonth);
                sUtilMonth = util.printd('mmmm', oMyDate);
                console.println('sUtilMonth mmmm: ' + sUtilMonth);
                // date
                var sUtilDate = util.printd('d', oMyDate);
                console.println('sUtilDate d: ' + sUtilDate);
                var sUtilDate= util.printd('dd', oMyDate);
                console.println('sUtilDate dd: ' + sUtilDate);
                // year
                var sUtilYear = util.printd('yy', oMyDate);
                console.println('sUtilYear yy: ' + sUtilYear);
                var sUtilYear = util.printd('yyyy', oMyDate);
                console.println('sUtilYear yyyy: ' + sUtilYear);

                • 5. Re: date separate year, month and day
                  evidal2 Level 1
                  I put this code in the field datesol in simple calculate field notation. is that correct?. because copy monthsol value of the month, the year the day yearsol and daysol

                   

                  • 6. Re: date separate year, month and day
                    gkaiseril MVP & Adobe Community Professional

                    Are you getting any errors in the JavaScript debugging console?

                     

                    You are using the syntax for the 'Custom JavaScript calculation' and this syntax can not be used in the 'simplified field notation. Also you can not use any JavaScript properties, objects, functions, control statments.

                     

                    When run in the console, I find you have a misspelling of the variable name 'datesol'. I also do not see where you are initializing the value for 'datesol'.

                     

                    var datesol = event.valueAsString;  // get value of this field

                    var array_datesol = datesol.split("/") ; // make into an array
                    this.getField('yearsol').value =array_datesol[2];  // get element year
                    this.getField('monthsol').value = array_datesol[1];  // get month element - fixed variable name
                    this.getField('daysol').value = array_datesol[0]; // get date element

                    I would use one of the following so the other fields are only updated when a date has been entered and the leading zeros are displayed:
                    this.getField('yearsol').value = '';
                    this.getField('monthsol').value = '';
                    this.getField('daysol').value = '';
                    if(event.value != '') {
                    // get parts of date and print with leading zeros
                    var datesol = event.value;  // get value of this field
                    var array_datesol = datesol.split('/') ; // make into an array
                    this.getField('yearsol').value = util.printf('%,304.0f', array_datesol[2]);  // get element year
                    this.getField('monthsol').value = util.printf('%,302.0f', array_datesol[1]);  // get month element - fixed variable name
                    this.getField('daysol').value = util.printf('%,302.0f', array_datesol[0]); // get date element
                    }

                     

                    // or

                    this.getField('yearsol').value = '';
                    this.getField('monthsol').value = '';
                    this.getField('daysol').value = '';
                    if (event.value != '') {
                    // get date parts and print with leading zeros
                    var oDatesol = util.scand('dd/mm/yyyy', event.value); // get date object
                    this.getField('yearsol').value = util.printf('%,302.0f',oDatesol.getFullYear());  // get element year
                    this.getField('monthsol').value = util.printf('%,302.0f', oDatesol.getMonth() + 1);  // get month element - fixed variable name
                    this.getField('daysol').value = util.printf('%,302.0f', oDatesol.getDate()); // get date element
                    }
                    // or
                    this.getField('yearsol').value = '';
                    this.getField('monthsol').value = '';
                    this.getField('daysol').value = '';
                    if(event.vaue != '') {
                    // get parts of date and format
                    var oDatesol = util.scand('dd/mm/yyyy', event.value); // get date object
                    this.getField('yearsol').value = util.printd('yyyy', oDatesol); // get element year
                    this.getField('monthsol').value = util.printd('mm', oDatesol); // get month element - fixed variable name
                    this.getField('daysol').value = util.printd('dd', oDatesol); // get date element
                    }
                    If you are going to fill other field, you will need to use the '.valueAsStriing' property or '.toString()'  method to retain the leading zeros.
                    1 person found this helpful
                    • 7. Re: date separate year, month and day
                      evidal2 Level 1
                      Thank you very much everybody, at the end with your answers I got it working.

                      var datesol = event.value;  // get value of this field

                      var array_datesol = datesol.split("/") ; // make into an array

                      this.getField('yearsol').value =array_datesol[2];  // get element year

                      this.getField('monthsol').value = array_datesol[1];  // get month element - fixed variable name

                      this.getField('daysol').value = array_datesol[0]; // get date element