Fetch number of years from range selected and distribute in fields

I have  a requirement where in the form i have date range: From date and To date. So if user selects from date as 01/01/2020 and to date as 0101/2022. It should display 2 fields for 2021 and 2020. Similarly , if from date is 01/04/2020 and to date is 02/05/2025, it should dispaly new fields for 2021,2022,2023,2024 and 2025. Maximum number of date range gap is 5, so max 5 fields can be displayed. Can i have some suggestion as to how this can be achieved?
1 answers

Hi Pragya,

  1. Create a non-persistable entity with 5 integer attributes Year1, Year2, Year3, Year4 and Year5
  2. Based on your cutoff month logic assign year-from-dateTime($StartDate) or year-from-dateTime($StartDate+/- 1) to the first attribute Year1
  3. Assign Year2 = Year1+1 
  4. Assign Year3=Year2+1   till the time the calculated year is less than  year-from-dateTime($EndDate)