4 Replies Latest reply on Mar 24, 2015 12:51 PM by hasand59089870

    Help with Dates (Number of Days in Month) and (Days Remaining in Month) - Document Attached

    ahlaj77 Level 1

      Once a user selects a date, would like them to be able to see the number of days in that particular month and as well the days remaining between the date selected and the end of the month.

      I have added code to my document but doesn't seem to be working . If someone could take a look at it, it would be much appreciated! Thanks!!

       

      Dropbox - Dates.pdf

        • 1. Re: Help with Dates (Number of Days in Month) and (Days Remaining in Month) - Document Attached
          gkaiseril MVP & Adobe Community Professional

          You date picker has the code for one technique to determine the number of days a month. That is why it can display the number of days in each month, well except for August.

           

          August has 31 days not 30. You need to update your script. The code also adjust February for leap years and leap centuries.

           

          Another approach would be create a date object for the selected date and then adjust the date object to the first day of the next month, and then adjusting the date item by a (-1) day.

          • 2. Re: Help with Dates (Number of Days in Month) and (Days Remaining in Month) - Document Attached
            ahlaj77 Level 1

            Thanks gkaiseril! I went ahead and updated the script from 30 to 31 (august). I will take a look at that.

             

            What would be the best way to get the remaining days in the month? For example if today is March 24, I would need to get the remaining days in a month (7 days). Trying to figure out that calculation :/

            • 3. Re: Help with Dates (Number of Days in Month) and (Days Remaining in Month) - Document Attached
              gkaiseril MVP & Adobe Community Professional

              function Scand(cFormat, cValue) {
              var oDate = util.scand(cFormat, cValue);
              return oDate;
              }

              // date string;
              var cToday = "24-Mar-2015";
              // date format for date string;
              var cDateFormat = "d-mmm-yyyy";
              // create date object for date;
              var oToday = Scand(cDateFormat, cToday);
              var nFullYear = oEndMonth.getFullYear();
              var nMonth = oEndMonth.getMonth();
              // create new date object for the next month less 1 day;
              oEndMonth = new Date(nFullYear, (nMonth + 1), -1);
              // get the last date of the month;
              var nEndDate = oEndMonth.getDate();
              // compute difference in value of end of month - today in days;
              // including the start and end days;
              var nDaysLeft = Math.floor(((oEndMonth.getTime() - oToday.getTime()) / (1000 * 60 * 60 * 24) ) + 1);

              // display some processing information;
              console.println("Today: " + cToday);
              console.println("Today Full Year: " + nFullYear);
              console.println("Today Month (zero based): " + nMonth);
              console.println("End of month: " +util.printd(cDateFormat, oEndMonth));
              console.println("Number of day in the month: "  + nEndDate);
              console.println("Days to end of the month: "  + nDaysLeft);

               

              You will have to edit the script to get the value of the input date and set the value for the days in the month and days left in the month.

              • 4. Re: Help with Dates (Number of Days in Month) and (Days Remaining in Month) - Document Attached
                hasand59089870 Level 2

                function monthlength(myDate) {
                  var xDate = new Date(myDate)
                  var zMonth = xDate.getMonth()
                  xDate.setDate(1)
                  xDate.setMonth(zMonth + 1)
                  xDate.setDate(0)
                  return xDate.getDate() }


                var myDate = ("2015,3,24")       
                or
                var myDate = new Date()
                or

                var myDate = this.getField("AgrrementDate").value
                this.getField("selected").value = myDate.getDate()
                this.getField("remaining").value = monthlength(myDate) - myDate.getDate()