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

How to auto calculate date fields from an inputted date

Community Beginner ,
Sep 14, 2020 Sep 14, 2020

Copy link to clipboard

Copied

Good Morning,

 

I am updating a form that requires dates to be inputted. It has a date range of 7 days starting on Sunday and ending on Saturday of every week. These are typically filled out the week after the stated date range. The first instances of a date is in the header with a period date range (from DATE to DATE). For the sake of argument lets say the date range is from 09/13/2020 to 09/19/2020. It then has a table that breaks down the range into a row for each day:

Sunday

09/13/2020___________

Monday

09/14/2020___________

....

....

Saturday

09/19/2020___________

 

Is there a way to format or calculate all of the dates after the first is inputted by the user so they don't have to select each drop down and input it themselves?

 

 

 

 

TOPICS
Create PDFs , How to , PDF forms

Views

7.6K

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 , Sep 14, 2020 Sep 14, 2020

Votes

Translate

Translate
Community Expert , Sep 14, 2020 Sep 14, 2020

Good deal!  Now we're talking.

 

To achieve this with JavaScript  you grab the value of  the date object and convert it to a srtring. 

 

To do this you use two methods (illustrated in full detail in the links posted earlier):

 

  • util.scand()
  • and util.printd()

 

Here's an example that I used in my PDFs from the links that try67 posted for you:

 

//declare your variables; get the date string from date field object
var f  = this.getField("myDateField").value;
var d = util.scand("mm/dd/yyyy", f);  
...

Votes

Translate

Translate
Community Expert ,
Sep 14, 2020 Sep 14, 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 Beginner ,
Sep 14, 2020 Sep 14, 2020

Copy link to clipboard

Copied

I feel like I am reading ancient sumarian trying to decipher how to do what I need to with those tutorials. I am a low level employee in a ginormous bureaucracy and do not get paid enough to pay for a script. Thank you though for trying to help.

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 ,
Sep 14, 2020 Sep 14, 2020

Copy link to clipboard

Copied

If you wish I could set it up for you in this one file for a reduced fee. You can contact me privately via [try6767 at gmail.com] to discuss it further.

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 ,
Sep 14, 2020 Sep 14, 2020

Copy link to clipboard

Copied

I live paycheck to paycheck. I'm not paying for this. I came here for help, not to be badgered by a salesman. This is a support community, not a place to drum up business.

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 ,
Sep 14, 2020 Sep 14, 2020

Copy link to clipboard

Copied

Sorry, didn't mean to "badger" you...

All the information you need to achieve it is in the links I provided. If you have a specific question about something from there we'll be happy to help you out, but it seems you want us to do your job for you for free, which is not likely to happen.

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 ,
Sep 14, 2020 Sep 14, 2020

Copy link to clipboard

Copied

My job isn't to code so no I don't want you to do my job for me for free. I wanted help because I am a glorified secretary asked to create a form. If you already know how it's done, how are you doing my job or any work to just tell me?

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 ,
Sep 14, 2020 Sep 14, 2020

Copy link to clipboard

Copied

If you don't want to pay there's plenty of posts in floating around somewhere in this community that certainly have all the answers and scripts that you 're asking about.

 

You just need to put more effort in searching for them.

 

Otherwise, you're basically asking for someone to do all the scripting work for you in which case is a way of outsourcing and should be paid for. In fact , a lot of ungrateful posters come here asking questions similar to your to what appears to be a simple subject, and then they keep adding more complicated subjects to the thread. In the end they didn't even have to lift a finger to even do the leg work.

 

If you noticed the three links that try67 posted for you are the tutorials that you need.

 

You must read a bit through them.

 

Using those three articles  is how I began learning Acrobat JavaScript scripting  in this forum .

So, If you're looking into learning JavaScript and be able to share a little piece of your code I'm pretty sure that a lot of people here would help 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 Beginner ,
Sep 14, 2020 Sep 14, 2020

Copy link to clipboard

Copied

Awesome, thank you! I was under the impression that the only things that pertained to my issue were the ones that popped up on the right side after I posted and I couldn't find a close enough answer there. I will do a more comprehensive search now that I know there may be more solutions that better match my issue elsewhere in this community. By the way, this is the only issue that I have and I can adjust it as need be if I just have something to start from (essentially how to add 1 day to a date from another field). Have a great day!

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 ,
Sep 14, 2020 Sep 14, 2020

Copy link to clipboard

Copied

So after several hours of trying to figure this all out, instead of trying to understand how to code, I just made the form in Excel. It's not as functional as a PDF, but it will work with a calulation instead of coding. Maybe one day I will learn to code, but something tells me I am not smart enough to figure it out. I barely passed a C++ class 10 years ago.

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 ,
Sep 14, 2020 Sep 14, 2020

Copy link to clipboard

Copied

Good deal!  Now we're talking.

 

To achieve this with JavaScript  you grab the value of  the date object and convert it to a srtring. 

 

To do this you use two methods (illustrated in full detail in the links posted earlier):

 

  • util.scand()
  • and util.printd()

 

Here's an example that I used in my PDFs from the links that try67 posted for you:

 

//declare your variables; get the date string from date field object
var f  = this.getField("myDateField").value;
var d = util.scand("mm/dd/yyyy", f);  

//add one day to the date string in "myDateField"

d.setDate(d.getDate()+1);  

//display the output of the new date in the desired date format
event.value = util.printd("mm/dd/yyyy", d);

 

You can use this a custom calculation script for each of the  fields you need to pupulate.

 

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
New Here ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

I want you to know ls rbls, if you ever see this, that I spent a good 2 hours trying to create a calculated date field.  The user inputs a date in one field, and the calculated field would auto-populate 30 days later.  Your formula above worked the first time.  SO GREAT!  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 ,
Aug 04, 2022 Aug 04, 2022

Copy link to clipboard

Copied

you're welcome

 

Happy to read that and all credit to the Adobe and community professionals in these forums.

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
New Here ,
Apr 27, 2023 Apr 27, 2023

Copy link to clipboard

Copied

Hi ls_rbls

Thank you for this. This has worked great for me. There's only one little question I have - I know I'm being lazy, but I don't have much knowledge around Javascript (basic HTML is the extent of my knowledge).

 

When I use your code, it automatically displays an end date regardless (the calculated date from today) of whether the "myDateField" is popluated - is there a way to have the output field blank where the "myDateField" is blank?

Apart from it looking nicer not already having some random date in it when people open, this is a form that may still be printed out and hand written by certain people, so again, would prefer not to have the date automatically appear.

 

Thanks in advance 🙂

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
New Here ,
Apr 27, 2023 Apr 27, 2023

Copy link to clipboard

Copied

Just as a follow up, I discovered this topic: https://community.adobe.com/t5/acrobat-sdk-discussions/get-field-to-remain-blank-until-user-enters-v...

 

And integrated the if statement and got the desired result. Thanks again for the initial code, still 🙂

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
New Here ,
Apr 30, 2023 Apr 30, 2023

Copy link to clipboard

Copied

Very informative .

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 ,
Apr 30, 2023 Apr 30, 2023

Copy link to clipboard

Copied

LATEST

Thank you for updating the thread!

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
New Here ,
Apr 28, 2023 Apr 28, 2023

Copy link to clipboard

Copied

Nice just what I needed, thanks for posting...who knew date calcs were so complicated, but you made it simple! A++

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 ,
Apr 29, 2023 Apr 29, 2023

Copy link to clipboard

Copied

You're welcome.

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