These forums are now Read Only. If you have an Acrobat question, ask questions and get help from one of our experts.

Adding Current Date and Future Date to a Text Field

pstechy
Registered: Dec 8 2009
Posts: 3
Answered

Hi there, hoping someone can help. I am trying to add a text field to a document that displays a simple message:

Printed on DD/MM/YYYY. Expires on DD/MM/YYYY.

Where the expiry date is 7 days after the current date. I am attempting to use a document-level javascript. My code is as follows to print the current date:

var f = this.getField("Today");
f.value = "Printed on " + util.printd("mm/dd/yyyy", new Date()) + ". This document expires in 7 days.";

Rather than printing "This document expires in 7 days.", I'd like to print something as above, "Expires on DD/MM/YYYY", which would be 7 days after the current date. I keep trying different methods and ending up with errors.

Any help with the code would be greatly appreciated.

Thanks,
Dan

My Product Information:
Acrobat Pro 8.0, Windows
try67
Expert
Registered: Oct 30 2008
Posts: 2398
You can try something like this:
  1. var f = this.getField("Today");
  2. var now = new Date();
  3. var oneWeekFromNow = new Date();
  4. oneWeekFromNow.setTime(now.getTime()+604800000); // 604800000 is 1 week in milliseconds
  5. f.value = "Printed on " + util.printd("mm/dd/yyyy", now) + ". This document expires on " + util.printd("mm/dd/yyyy", oneWeekFromNow);

- AcrobatUsers Community Expert - Contact me personally at try6767 [at] gmail [dot] com
Check out my custom-made scripts website: http://try67.blogspot.com

pstechy
Registered: Dec 8 2009
Posts: 3
Wow. Such a quick response, and exactly what I was looking for. Works perfectly, thanks so much!