1 Reply Latest reply on Nov 13, 2008 8:30 AM by gkaiseril

    Self Populating Date in Form Fields...help...help...help

      I have a employee time sheet form which is not nearly as efficient as it could be, wasting time to document time!!
      To complete the form the user has to manually enter the date in three different fields, year, month and day.
      Because this is a hours worked form, the user then needs to re-enter the day (not month and year) into seven different fields across the form and fill in the hours worked.
      I would like to set the properties of the day fields to take information for the three fields at the top of the form which contain the year, month and day. I would like to populate the seventh field (last Friday of the work week) with the day as mentioned above, and ask the other six fields to self populate in ascending order. I tried it as a simple math equation, but it does not account for some months having 31/30 or 28 days.

      I have tried to complete a small script myself, and I am out of my league.
      Here is what I tried:
      var x=newDate (yy, mm, dd);
      var day=1000*60*60*24;
      var prev=x.getTime()-day;
      var prev day=newDate(prev);
      var y+prev day.format ("d")

      Please resist the urge to call me an idiot and lend a hand if you can.
      Leagues of colleagues will appreciate you like crazy and can spend their time wasting potential on something else :)

        • 1. Re: Self Populating Date in Form Fields...help...help...help
          gkaiseril MVP & Adobe Community Professional
          Do not feel bad, JavaScirpt's Date Time object is very confusing and complex. One needs to keep track of exactly what one is working with, the object of the value of the object. then one has the choice of using JavaScript's date methods or computing in milliseconds and using Acrobat JavaScirpt's "util.printd()" method to format the result

          // computations using JavaScirpt's date time object and methods:
          var oDate = new Date(); // get the current date's object
          console.println("Today is: " + oDate);
          var vDate = oDate.getDate(); // get the date of the month
          console.println("Today's date is: " + vDate);
          console.println("The month for today is: " + (oDate.getMonth() + 1) );
          console.println("The year for today is: " + oDate.getFullYear() ); // the 4 digit year
          // create the date time object for yesterday
          var oYesterday = new Date(vFullYear, vMonth, (vDate - 1) ); // create date time object for yesterday
          console.println("Yesterday was: " + oYesterday);
          var vYDate = oYesterday.getDate(); // get the date of the month
          console.println("Yesterday's date was: " + vYDate);
          console.println("The month for yesterday was: " + (oYesterday.getMonth() + 1) );
          console.println("The year for yesterday was: " + oDate.getFullYear() ); // the 4 digit year

          // computing guising milliseconds and using the util.printd() method:
          var oDate = new Date(); // todays date time object
          var fDate = oDate.valueOf(); // the milliseconds from the date time object's epoch date
          console.println("The current date and time is: " + oDate)
          var sToday = util.printd("dd", oDate);
          console.println("Today's date: " + sToday);
          console.println("Today's month: " + util.printd("mm", oDate) ); // display the result
          console.println("Today's year: " + util.printd("yyyy", oDate) ); // display the result
          console.println("Milliseconds for now = " + fDate);
          var v1Day = 1000 * 60 * 60 * 24; // milliseconds in one day
          var vDay = (fDate / v1Day); // today's days since the Epoch date
          console.println("It has been " + vDay + " since the Epoch date.");
          var vYDay = vDay - 1; // yesterday's days since epoch date
          console.println("Yesterday was " + vYDay + " since the Epoch date."); // show result
          var oYesterday = new Date(vYDay * v1day) // create yesterday's date time object
          console.println("Yesterday's date: " + oYesterday); // show result
          var sYDate = util.printd("dd", oYesterday); // get the date
          console.println("Yesterday's date: " + sYDate); // display the result
          console.println("Yesterday's month: " + util.printd("mm", oYesterday) ); // display the result
          console.println("Yesterday's year: " + util.printd("yyyy", oYesterday) ); // display the result