0 Replies Latest reply on Jan 6, 2016 12:19 PM by mmb5588

    Javascript Mod for Acrobat Form - Weeks Remaining

    mmb5588

      So I found this great javascript (below) that returns Weeks Remaining This Year from  Source: http://weeknumber.net/how-to/javascript  with the usage release // This script is released to the public domain and may be used, modified and // distributed without restrictions. Attribution not necessary but appreciated.       

       

      In my Acrobat form, I need the calculation to function off of a manually entered form field called "Todays_Date" that will be entered by the user. I can't seem to figure out how to modify the code to make that happen. It's probably right in front of my face but any help would be greatly appreciated.

       

      // Returns the ISO week of the date.

      Date.prototype.getWeek = function() {

        var date = new Date(this.getTime());

         date.setHours(0, 0, 0, 0);

        // Thursday in current week decides the year.

        date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);

        // January 4 is always in week 1.

        var week1 = new Date(date.getFullYear(), 0, 4);

        // Adjust to Thursday in week 1 and count number of weeks from date to week1.

        return 1 + Math.round(((date.getTime() - week1.getTime()) / 86400000

                              - 3 + (week1.getDay() + 6) % 7) / 7);

      }

       

      // Returns the four-digit year corresponding to the ISO week of the date.

      Date.prototype.getWeekYear = function() {

        var date = new Date(this.getTime());

        date.setDate(date.getDate() + 3 - (date.getDay() + 6) % 7);

        return date.getFullYear();

      }