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

HOW DO I ADD 6 MONTHS TO CURRENT DATE!

Community Beginner ,
Nov 30, 2020 Nov 30, 2020

Copy link to clipboard

Copied

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

TOPICS
Acrobat SDK and JavaScript

Views

2.1K

Translate

Translate

Report

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

correct answers 2 Correct answers

Community Expert , Nov 30, 2020 Nov 30, 2020

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);}

Votes

Translate

Translate
Community Expert , Nov 30, 2020 Nov 30, 2020

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

 

Votes

Translate

Translate
Community Beginner ,
Nov 30, 2020 Nov 30, 2020

Copy link to clipboard

Copied

The price "day" is not important.

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

Votes

Translate

Translate

Report

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 ,
Nov 30, 2020 Nov 30, 2020

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

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 ,
Nov 30, 2020 Nov 30, 2020

Copy link to clipboard

Copied

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);}

Votes

Translate

Translate

Report

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 Beginner ,
Nov 30, 2020 Nov 30, 2020

Copy link to clipboard

Copied

Thanks Nesa!

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

Votes

Translate

Translate

Report

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 Beginner ,
Nov 30, 2020 Nov 30, 2020

Copy link to clipboard

Copied

Hi Nesa,

I am getting an error with the format of the expiry date.

I need it to be "May 30, 2010" (mmm d, yyyy)

Votes

Translate

Translate

Report

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 ,
Nov 30, 2020 Nov 30, 2020

Copy link to clipboard

Copied

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

 

Votes

Translate

Translate

Report

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 Beginner ,
Nov 30, 2020 Nov 30, 2020

Copy link to clipboard

Copied

...and my stamp is perfect!

I know nothing about coding so thanks a million!

Votes

Translate

Translate

Report

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
Enthusiast ,
Nov 30, 2020 Nov 30, 2020

Copy link to clipboard

Copied

If you are satisfy with an answer pls mark as correct so others can find them.

Votes

Translate

Translate

Report

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 Beginner ,
Dec 01, 2020 Dec 01, 2020

Copy link to clipboard

Copied

Oh! Sure thing.

Votes

Translate

Translate

Report

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
Participant ,
Aug 24, 2023 Aug 24, 2023

Copy link to clipboard

Copied

Hey guys, I used the code but it doesn't work in the iPad nor in the iOs. Do you know why? Do I have to change the code?

Votes

Translate

Translate

Report

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 ,
Aug 24, 2023 Aug 24, 2023

Copy link to clipboard

Copied

Because the mobile versions of Acrobat support almost no scripting, unfortunately.

Try PDF Expert by Readdle and there's a better chance it will work there.

Votes

Translate

Translate

Report

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
Participant ,
Aug 25, 2023 Aug 25, 2023

Copy link to clipboard

Copied

Thank you!

 

Votes

Translate

Translate

Report

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
Participant ,
Oct 10, 2023 Oct 10, 2023

Copy link to clipboard

Copied

Hey guys,

 

What if I would like the date to be always the 1st day of the 13th month? Is that possible?

 

Votes

Translate

Translate

Report

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 ,
Oct 10, 2023 Oct 10, 2023

Copy link to clipboard

Copied

Sure. After this line:

sixmonth.setMonth(sixmonth.getMonth()+6);

Add:

sixmonth.setDate(1);

Votes

Translate

Translate

Report

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
Participant ,
Oct 13, 2023 Oct 13, 2023

Copy link to clipboard

Copied

LATEST

Thank you : )

Votes

Translate

Translate

Report

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 ,
Nov 30, 2020 Nov 30, 2020

Copy link to clipboard

Copied

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. 

Votes

Translate

Translate

Report

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 Beginner ,
Nov 30, 2020 Nov 30, 2020

Copy link to clipboard

Copied

Thank you karl!

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

Votes

Translate

Translate

Report

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