2 Replies Latest reply on Oct 28, 2012 8:17 AM by MarkWalsh

    Get last day of month

    radajo89

      I am complete new and have very limited knowledge of Javascript.

      My question is how can I get the last day of the current month but 2 years in the future when a pdf form is opened.

       

      Thanks in advance,

      radajo

        • 1. Re: Get last day of month
          try67 MVP & Adobe Community Professional

          You take the current time, and:

          - add two years to it

          - if the current month is December, add another year and change it to

          January

          - otherwise, add one month

          - set the date to the 1st

          - deduct 24 hours

          Then you have the last day of the current month, 2 years in the future.

          • 2. Re: Get last day of month
            MarkWalsh Level 4

            No need to check the month and adjust the year manually, the date automatically does this.

             

            Just add 25 months to the first of the current month, then subtract a day:

             

            var d = new Date(); // Get current date

            d.setDate(1); // Set to first day of current month

            d.setMonth(d.getMonth() + 25); // Add 25 months (2 years + 1 month)

            d.setDate(d.getDate() - 1); // Subtract a day to get last day of previous month

             

            event.value = d.toDateString();