Skip to main content
Participating Frequently
September 14, 2020
Answered

How to auto calculate date fields from an inputted date

  • September 14, 2020
  • 1 reply
  • 13903 views

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?

 

 

 

 

Correct answer ls_rbls

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.


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.

 

1 reply

try67
Community Expert
September 14, 2020
Participating Frequently
September 14, 2020

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.

ls_rbls
ls_rblsCorrect answer
Community Expert
September 14, 2020

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.


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.