Skip to main content
GOLO Grenada
Participating Frequently
Nov 30, 2020 5:19 PM UTC
Answered

HOW DO I ADD 6 MONTHS TO CURRENT DATE!

Good day,

I designed a dynamic stamp with 3 fields;

- the current date "_Date"

- the current time "_Time"

- the expiry date "_ExpDate"

I need the expiry date to be 6 months from the current date.

Can someone provide a javascript to calculate the expiry date?

 

K. Gibbs

This topic is closed to new replies. Start a new post to keep the conversation going.
Nesa Nurani
Nesa NuraniCorrect answer
Community Expert
Nov 30, 2020 7:27 PM UTC

In code just change "mm/yyyy" to "mmm d,yyyy".

 

17 replies

Karl Heinz  Kremer
Community Expert
Community Expert
Nov 30, 2020 6:20 PM UTC

You received some good information. Let me add some general thoughts: When it comes to dates in Acrobat's JavaScript, you are dealing with "normal" JavaScript, and can research how this particular problem can be solved in JavaScript - without having to limit your search to Acrobat. The "Date" object is part of the core JavaScript language. Any JavaScript implementation consists of two parts: The core language and any potential domain specific extensions. In the web browser, these extensions would deal with web pages and HTML, wheras in Acrobat these exensions are all about PDF documents. But both implementations would provide the same level of support for the Date object - and therefore date specific manipulations. 

Translate
GOLO Grenada
Participating Frequently
Nov 30, 2020 6:57 PM UTC

Thank you karl!

I do research other forums online but many times their advice or solutions do not work.

Translate
Nesa Nurani
Community Expert
Community Expert
Nov 30, 2020 6:02 PM UTC

You can use this as custom calculation script of Expiry date field:

var today = this.getField("_Date").valueAsString;
if(today == "") event.value = "";
else{
var sixmonth = util.scand("mm/dd/yyyy", today);
sixmonth.setMonth(sixmonth.getMonth()+6);
event.value = util.printd("mm/yyyy", sixmonth);}

Translate
GOLO Grenada
Participating Frequently
Nov 30, 2020 7:07 PM UTC

Thanks Nesa!

I will slap that in and get back to you with the result.

Translate
GOLO Grenada
Participating Frequently
Nov 30, 2020 5:24 PM UTC

The price "day" is not important.

I am more interested in the 'month' and 'Year'.

Translate