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

Trying to subtract 1.5 hours from a set time field in Acrobat

Community Beginner ,
Feb 27, 2023 Feb 27, 2023

Copy link to clipboard

Copied

I have a manually entered time field h:MM tt but I want it to populate another field but deducting 1.5 hours.

 

Example: "Day1startTime" is 8:00 am, minus 1.5 hours should autopopulate "Day1arrivalTime" 6:30am

 

Can someone please help me!

 

 

TOPICS
How to , JavaScript , PDF forms

Views

1.2K

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 ,
Feb 27, 2023 Feb 27, 2023

Copy link to clipboard

Copied

Here's one technique that uses the date object. 

 

This code is for a custom valdate script on the "Day1startTime" field, where the time value is entered. 

 

var strArrTime = "";

var oTimeNow = util.scand("dd/mm/yy h:MM tt","01/01/23 " + event.value);

if(oTimeNow && !isNaN(oTimeNow.getTime()))
{
    oTimeNow.setMinutes(oTimeNow.getMinutes() - 90);
    strArrTime = util.printd("h:MM tt",oTimeNow);
}
this.getField("Day1arrivalTime").value = strArrTime;

 

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

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 ,
Feb 27, 2023 Feb 27, 2023

Copy link to clipboard

Copied

Thank you so much! That worked perfectly!

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 ,
Feb 27, 2023 Feb 27, 2023

Copy link to clipboard

Copied

Could you help me with one more thing?

 

Is it possible that the "Day1ArrivalTime" shows blank if there is no time in the Day1startTime? Right now if I don't enter a time the Arrival time automatically shows 10:30pm. (I guess it assumes that no entry on Day1start time is midnight).

 

Thanks again!

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 ,
Feb 28, 2023 Feb 28, 2023

Copy link to clipboard

Copied

LATEST

Use this:

 

if (event.value=="") this.getField("Day1arrivalTime").value = "";

else {

// put Thom's code here

}

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