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

Javascript code for a button to calculate 30 days from today.

New Here ,
Feb 14, 2018 Feb 14, 2018

could someone point me in the right direction with the javascript code that I would put into a buttons actions to calculate 30 days from "date" field and output it to a field called "first_payment_date"

TOPICS
PDF forms
711
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 ,
Feb 14, 2018 Feb 14, 2018
LATEST

One of the problems with dates is that they can be formatted in a lot of different ways. So, in order to calculate a future date, the date string in the field has to be converted to a Date object, which means you have to know the format of the date up front.

For the code below the date is assumed to be in the standard dd/mm/yyyy format. You'll need to modify this for your particular form.

var strDate = this.getField("date").value;

if(strDate != "")

{

    var dtStart = util.scand("dd/mm/yyyy",strDate);

    var dtNext = new Date(dtStart);

    dtNext.setDate(dtStart.getDate() + 30);

    this.getField("first_payment_date").value = util.printd("dd/mm/yyyy",dtNext);

}

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

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