11 Replies Latest reply on Jun 29, 2008 6:37 PM by (Brenda_Burden)

    How do I add this script to change an experation date!

      Hello,

      I have used a script on my website for some coupons that expire two days after the date on the person that is veiwing them on there computer using the date on their computer (makes people get ahold of me quicker because the coupon expires quickly0.

      I am kind of new to scripting I have gone into LIveCycle I have Acrobat 8 installed. What I want to do is put this script in place for a date where there is text. Can anyone help me out with this I'd really appreciate it!! The script is as follows.



      Thanks in advance
        • 1. Re: How do I add this script to change an experation date!
          Bernd Alheit Adobe Community Professional & MVP
          When you post HTML comments nobody can read your code.
          • 2. Re: How do I add this script to change an experation date!
            gkaiseril MVP & Adobe Community Professional
            One post is enough to get an answer.

            Do you want the coupon expiration date to appear on the coupon?

            Use the Date Time object within Acrobat JavaScript to populate this field.

            Or

            Do you want the PDF to no longer work?

            Then you need to use the LiveCycle Server product to manage the digital rights. Although there is a limited JavaScript cover that could be used but turning off JavaScript in Acrobat/Reader renders this useless.

            If you are going to use LiveCycle Designer, you have a choice of using FormCalc or JavaScript. Each handles the date/time object a little differently. FormCalc handles date calculations by the number of days and JavaScript uses milliseconds.

            There should be plenty of post about doing this type of calculation. One should also be careful about how the form field is formatted and being aware there is a difference between using "rawValue" and "formattedValue" properties.
            • 3. Re: How do I add this script to change an experation date!
              Level 1
              I would like the experation date to appear on the coupon.
              I do have a coupon page on my website where I have used java script to have the date acouple of days ahead show up on the web page with the coupons on it.
              Here is a link to the page so you can see what I am doing now and what I want to do in Acrobat thru LiveCycle Designer

              http://www.uptownimports.com/promotions.html

              Sorry about the multiple posts!!

              This is the code below.

              JavaScript Date Display

              //Just Copy the javascript code code below and put it between the
              and  tags of //your html page.

              function dispDate(dateVal) {
              DaystoAdd=dateVal
              TodaysDate = new Date();
              TodaysDay = new Array('Sunday', 'Monday', 'Tuesday','Wednesday', 'Thursday', 'Friday', 'Saturday');
              TodaysMonth = new Array('January', 'February', 'March','April', 'May','June', 'July', 'August', 'September','October', 'November', 'December');
              DaysinMonth = new Array('31', '28', '31', '30', '31', '30', '31', '31', '30', '31', '30', '31');
              function LeapYearTest (Year) {
              if (((Year % 400)==0) || (((Year % 100)!=0) && (Year % 4)==0)) {
              return true;
              }
              else {
              return false;
              }
              }
              CurrentYear = TodaysDate.getYear();
              if (CurrentYear < 2000)
              CurrentYear = CurrentYear + 1900;
              currentMonth = TodaysDate.getMonth();
              DayOffset = TodaysDate.getDay();
              currentDay = TodaysDate.getDate();
              month = TodaysMonth[currentMonth];
              if (month == 'February') {
              if (((CurrentYear % 4)==0) && ((CurrentYear % 100)!=0) || ((CurrentYear % 400)==0)) {
              DaysinMonth[1] = 29;
              }
              else {
              DaysinMonth[1] = 28;
              }
              }
              days = DaysinMonth[currentMonth];
              currentDay += DaystoAdd;
              if (currentDay > days) {
              if (currentMonth == 11) {
              currentMonth = 0;
              month = TodaysMonth[currentMonth];
              CurrentYear = CurrentYear + 1
              }
              else {
              month =
              TodaysMonth[currentMonth+1];
              }
              currentDay = currentDay - days;
              }
              DayOffset += DaystoAdd;
              function offsettheDate (offsetCurrentDay) {
              if (offsetCurrentDay > 6) {
              offsetCurrentDay -= 6;
              DayOffset = TodaysDay[offsetCurrentDay-1];
              offsettheDate(offsetCurrentDay-1);
              }
              else {
              DayOffset = TodaysDay[offsetCurrentDay];
              return true;
              }
              }
              offsettheDate(DayOffset);TheDate = DayOffset + ', ';
              TheDate += month + ' ';
              TheDate += currentDay + ', ';
              if (CurrentYear<100) CurrentYear="19" + CurrentYear;
              TheDate += CurrentYear;
              document.write(' '+TheDate);
              }



              //Then just call the function at the point you want the date to display, like so:

              dispDate(0)


              //The number in the brackets is the number of days you want to add to the current date.


              Thanks in advance
              John
              • 4. Re: How do I add this script to change an experation date!
                gkaiseril MVP & Adobe Community Professional
                For the LiveCycle Designer form:

                Far to complex.

                In FormCalc with a formatted date field of "MMM DD, YYYY" the calculation script:

                $.formattedValue = Num2Date(Date + 2, "MMM DD, YYYY")

                For JavaScript:

                var oExpire = new Date(new Date().valueOf() + (2 * 24 * 60 * 60 * 1000)); // today's date plus 2 days in milliseconds
                $.formattedValue = util.printd("MMM DD, YYYY", oExpire, true); // formatted expiration date

                or for HTML, Acrobat AcorForm, or LiveCycle Designer a funciton to advance today's date by a passed number of days:

                function ExpireDate(fNumDays) {
                var Now = new Date(); // get today's date time object
                var nFullYear = Now.getFullYear(); // get the full year from the object
                var nMonth = Now.getMonth(); // get the month from the object
                var nDate = Now.getDate(); // get the date from the object
                return new Date(nFullYear, nMonth, nDate + 2); // return date time object advanced by fNumDays
                }
                • 5. Re: How do I add this script to change an experation date!
                  Level 1
                  Geo,

                  I tried the FormCalc script but it did not work when I preview there is an error in the script, the short of it is below

                  error: accessor 'Date' is unknown

                  Can you try to run the script to see if it works for you?

                  JOhn
                  • 6. Re: How do I add this script to change an experation date!
                    gkaiseril MVP & Adobe Community Professional
                    My mistake, I forgot the "()":

                    $.formattedValue = Num2Date(Date() + 2, "MMM DD, YYYY")
                    • 7. Re: How do I add this script to change an experation date!
                      tweaked_eye Level 1
                      I have very little experience script in Acrobat or Live Cycle....Could you break down the steps.....?

                      1) Do I drop a Date/Time Field on to the Live Cycle artboard?

                      2) Change my caption to Coupon expires _____________

                      3)Under the Value Tab, do I toggle Type=Calculated - Read Only?

                      4)Then, toggle Calculation script?

                      5) Then, under the Binding tab I sorta get lost...

                      Thanks for any help.
                      • 8. Re: How do I add this script to change an experation date!
                        tweaked_eye Level 1
                        I am not opposed to doing this in Acrobat either.....
                        • 9. Re: How do I add this script to change an experation date!
                          tweaked_eye Level 1
                          TOTAL COOLNESS...I figured it out...this is *******.
                          • 10. Re: How do I add this script to change an experation date!
                            Rufus Dufus, can you tell me how you solved this problem. I am needing to enter a date1 and then have the dat2 be 30 days from that day.

                            Thank you
                            • 11. Re: How do I add this script to change an experation date!
                              Level 1
                              Thanks to all, I finally got it figure out. It took me a moment to understand what I was doing, but I am one of those folks, that will never take no as a final answers.