7 Replies Latest reply on Jul 2, 2010 8:46 AM by Jerry62712

    How do I work with dates?

    Jerry62712 Level 1

      I've tried several formcalc and javascript methods, but none of them have worked for me so far.  What I want to do is take the current date and extract the month and year.  Then I will use these to test against other values.  An alternative is to build some dates and compare them to the current date.  That date can be changed by the user after the initial display of the form.

       

      In psuedo code it would look like this:

       

      // currently in the minimum wage field

      // MonthYear field is initially set to the current date, but can be changed by the user

      var curDate = MonthYear;

      var prior10Date = "07/01/2010";

      var prior09Date = "07/01/2009";

       

      if (curDate > prior10Date) then

           this.rawValue = 8.25;

      else

      if (curDate > prior09Date) then

           this.rawValue = 8.00;

      else

           this.rawValue = 7.75;

        • 1. Re: How do I work with dates?
          Jerry62712 Level 1

          Moderators - please delete this as it is in the wrong forum.

          • 2. Re: How do I work with dates?
            AKloft

            I would reference this: http://www.w3schools.com/js/js_obj_date.asp:

             

            var myDate=new Date();
            myDate.setFullYear(2010,0,14); //January 14, 2010
            var today = new Date(); //today

            if (myDate>today)
            {
            alert("Today is before 14th January 2010");
            }
            else
            {
            alert("Today is after 14th January 2010");
            }
            • 3. Re: How do I work with dates?
              Jerry62712 Level 1

              Thanks for the reply.  I've asked the forum moderators to delete the thread as I foolishly put this message in the wrong place.  I'm reposting it in the Designer forum.

               

              BTW, I get an error when I try to post the value to the field.  "syntax error near token minWage":

              this = minWage;

              • 4. Re: How do I work with dates?
                AKloft Level 2

                The code I supplied is Javascript,  if minWage is the field you are in, i.e., Form.subform.minWage::exit(Javascript), you will want your value setting to be:

                 

                this.rawValue = this.rawValue;   // a bit redundant really, so you could exclude it completely.

                 

                or if minWage is a variable within scope of the script, then:

                 

                this.rawValue = minWage;

                 

                If you give me the whole section, or upload your form to Acrobat.com I can help you out further.

                 

                Thanks,

                Alex

                 

                The moderators will probably just move the thread, so filling out this one is still fine.

                • 5. Re: How do I work with dates?
                  Jerry62712 Level 1

                  I've tried it both ways (formcalc and javascript).  Here is the current version:

                   

                  // WVSWEW.WEWsubform.StateMinimumWage::initialize

                  // JavaScript Client

                  // workDate will be set to another field (datetime format) that the user

                  // can modifiy and the whole form updated with new values at that time

                   

                  var workDate = new Date();
                  var prior10Date = new Date(2010,07,01);
                  var prior09Date = new Date(2009,07,01);
                  var minWage = 8.25;

                   

                  if (workDate < prior10Date) then
                      minWage = 8.00;        // last year amount
                     
                  if (workDate < prior09Date) then
                      minWage = 7.75;        // prior year amount

                   

                  this = minWage;

                   

                  The error in the last line is:

                  Error: syntax error near token "minWage" on line 13, column 14

                  • 6. Re: How do I work with dates?
                    AKloft Level 2

                    http://acrobat.com  sign in and you can upload files to that

                     

                    or you can PM me your e-mail address and I can send you an invite to share a workspace with me and upload your form to that

                    • 7. Re: How do I work with dates?
                      Jerry62712 Level 1

                      I've posted the reply in the Designer forum...