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

Custom Date Format that gives a range of years

New Here ,
Mar 15, 2021 Mar 15, 2021

Copy link to clipboard

Copied

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

 

2 years_example.jpg

 

2 years_DateField.jpg

 

 

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.

Views

963

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 ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

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.

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 ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

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

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 ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

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.

 

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 ,
Mar 16, 2021 Mar 16, 2021

Copy link to clipboard

Copied

Sorry, but where is the "Today" error? Also, the script for "Year 2" gives 2019 and the script for "Year 1" gives 2020. Like the Current Year at the top of the page 2020-2021, "Year 2" and "Year 1" should be calculated as 2018-2019  and 2019-2020, respectively. Sorry to bother you 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 ,
Mar 17, 2021 Mar 17, 2021

Copy link to clipboard

Copied

LATEST

Open the JS Console and you'll see the error message.

The code I provided uses the current year, as I did not see which field you're referring to. Please provide the exact field name.

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