Skip to main content
williamblanch
Participating Frequently
March 16, 2021
Question

Custom Date Format that gives a range of years

  • March 16, 2021
  • 1 reply
  • 1885 views

I need help with writing a javascript to create a Custom Date Format or a Custom Category that sets a 1 year range:

 

 

 

 

So, the format that should look something like  yyyy - yyyy+1. The top range is 2 years back from the year the application was filled out and the bottom range is 1 year back.

 

Attached is the form that I would like to modify. The entry in question is on page 10 of the Application Form.

    This topic has been closed for replies.

    1 reply

    try67
    Community Expert
    Community Expert
    March 16, 2021

    You can't use the Date format for this. You'll need to write your own Format (and Validate) scripts to achieve it.

    However, if the values all depend on the year the form was filled in then you might as well use a calculation script and do it automatically for the user.

    williamblanch
    Participating Frequently
    March 16, 2021

    Hello and thanks for the prompt answer. It would be great if the entries for the years were automatic depending on the current year. I am not that versed in javascript, I would appreciate it if you could help me with the calculation script. Or tell me where I can get the help if you don't write script for people. I have attached my "working on" copy of the application if it might help. Again it is on page 10, #3 and the current year is at the top of every page. Thanks!

     

    Billy (510) 329-4891

    William J Blanch
    try67
    Community Expert
    Community Expert
    March 16, 2021

    First of all, you have an error in the "Today" doc-level script which you should fix.

    So assuming it's the "Year 1" and "Year 2" fields you can use this code as a doc-level script:

     

    this.getField("Year 1").value = new Date().getFullYear()-1;

    this.getField("Year 2").value = new Date().getFullYear()-2;

     

    You'll need to change their Format to None, though.