5 Replies Latest reply on May 24, 2013 11:35 AM by gkaiseril

    date - 1 day

    MBCL63

      Hello,

       

      currently i'm using code below for date:

       

      var f = this.getField("Text29");

      f.value = util.printd("dd.mm.yyyy", new Date());

       

      I want to edit this code, so date would be new Date - 1 day..so if today is 24.5 i want to show 23.5

       

      thanks for help

        • 1. Re: date - 1 day
          gkaiseril MVP & Adobe Community Professional

          What is a 0.5 day?

           

          12 hours or 12.303164277142676 hours (adjustment for leap years and centuries).?

           

          Have you looked at what your code does?

           

          It does not create the date object for the value of the field.

           

           

          Try the following custom calculation script and observe the console display:

           

          var f = this.getField("Text29"); // get field object;
          console.show(); // show console for messages;
          console.clear(); // clear console;
          console.println( "formatted system date: " + util.printd("dd.mm.yyyy", new Date())); // format system date;
          console.println("system date: " + (new Date())); // print value of system date;

          var cDate = this.getField("Text29").valueAsString; // get date string value from field;
          console.println("Text29 value: " + cDate); // print field value;
          var oDate = util.scand("dd.mm.yyyy", cDate); // convert to date oobject;
          console.println("date object of Text29 value: " + oDate); // display field's date object;
          var nDate = oDate.getDate(); // get date of month from date object;
          console.println("Date number from date object: " + nDate); // display date of month value;
          nDate--; // decrement by 1 the date value;
          oDate.setDate(nDate); // set date for date object to new date value;
          console.println("Adjusted date: " + oDate);
          event.value = util.printd("dd.mm.yyyy", oDate);

          1 person found this helpful
          • 2. Re: date - 1 day
            MBCL63 Level 1

            Hello GKaiseril,

             

            my code works ok, it shows current date, and i just want to change my code so if today is 24.5 i want that script show 23.5, so current date - 1 day is the thing i need.

            • 3. Re: date - 1 day
              gkaiseril MVP & Adobe Community Professional

              You did not clearly state what you want to accomplish. Most users who post here want to enter a date into a field and then adjust the date by some date time value.

               

              So you want to decrement the system date by one day. You should also describe in which action your script is running as this will affect the coding.

               

               

              var oDate = new Date(); // get system date as date object;

              console.println("System date: " + oDate); // display system date;

              // adjust date object by -1 day;

              oDate.setDate(oDate.getDate() - 1);

              console.println("System date - 1 day: " + oDate);

               

              You can adjust the script as needed to put the result of the calculation as needed.

               

              Note the time for the date object is not altered.

              1 person found this helpful
              • 4. Re: date - 1 day
                MBCL63 Level 1

                Hi, sorry i though you would understand what i want.

                 

                I copied your last code into custom calculation sprint, but can't get it work...i want when i open document that in Text42 field would be currentdata-1day. Can i do that with custom calculation code?

                • 5. Re: date - 1 day
                  gkaiseril MVP & Adobe Community Professional

                  Look in the JavaScript console.

                   

                  var oDate = new Date(); // get system date as date object;

                  console.println("System date: " + oDate); // display system date;

                  // adjust date object by -1 day;

                  oDate.setDate(oDate.getDate() - 1);

                  console.println("System date - 1 day: " + oDate);

                  this.getField("Text29").value = util.printd("dd.mm.yyyy", oDate); // set the field value;