Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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:
Copy link to clipboard
Copied
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).