Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How do I create a text field that auto-populates the last day of the previous month?

New Here ,
Jul 01, 2022 Jul 01, 2022

I am trying to have a self updating PDF that will populate the date with the previous months last day.

 

If todays date is 6/23/22 then when I open the pdf I would like it to populate 5/31/22. So that any time I open the PDF in the month of June, the date will show the last of May and so on for any month. I work on reports and I am alwasy working in the previous month, so this would be a huge help.

 

Idealy I would like the range of the previous month as well, so if I open the pdf in June the date range will auto populate to 05/01/22 - 05/31/22. i am assuming this can be solved by using two text fields but the code would be appreciated.

 

Thanks in advacne to anyone who can help me.

TOPICS
Acrobat SDK and JavaScript
394
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 03, 2022 Jul 03, 2022

See the answer from ACP NesaNurani in the thread linked below:

 

 

You may be able to use a similar approach.

 

There are different ways to work around date calculations with JavaScript.

 

In your particular case, the intended workflow may need a document-level script.

 

Check out this old thread with additional guidance:

 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 11, 2022 Jul 11, 2022
LATEST

The basic trick to do it is to set the month to one month after the one you're interested in, and then set the date to 0, which will cause it to roll back to the last day before the first of that month, like this (let's say we want to know the last day of the current month):

 

var d = new Date();
d.setMonth(d.getMonth()+1);
d.setDate(0);
console.println(util.printd("mm/dd/yyyy", d));

This will print out "07/31/2022" (today, at least).

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines