21
Views
8
Comments
Solved
Generate a list of months from a given date up to present month
Question

Hi. So I have a dropdown that I must list months from that day an investor registered till date so they can see their monthly statements. So if someone registered this January, the list must just have January. If we are now in March it must have Jan to March (must include current month.

If someone registered in November and we are in February the list must have (Nov, Dec, Jan and Feb)

How best can I generate this list?

mvp_badge
MVP
Rank: #78
Solution

Hi Rudo,

In addition to the  João solution, I just want to share one more logic that I framed for the mentioned use-case.

See this Sample App | DynamicMonthDropdown

Please refer to the attached .oml file


As per the João solution, there is a possibility to get duplicate month record appended in the Monthlist variable

 i.e. if the year diff between date2 and date1 is more than 1, the loop will append duplicate month value. For that, you can either define an additional logic to either terminate the loop or to prevent duplicay or else you can add a ListDistinct action after the loop to get the final unique month list from the MonthList variable.


Hope this helps you!


Kind regards,

Benjith Sam

RWALabDynamicMonthDDList.oml

Rank: #70
Solution

Hi RUDO,


You can iterate through the dates and adding the months to a list, something like this:


Note that on adding the month to a list, you can take advantage of the FormatDateTime function to format the date as of your liking, in this case "MMM" will produce Jan, Feb, etc.


Check the action GenerateMonths, which given two dates generates the list of months in between, in the OML in attachment.


Hope it helps.


Regards,
João

ExampleMonthList.oml

mvp_badge
MVP
Rank: #78
Solution

Hi Rudo,

In addition to the  João solution, I just want to share one more logic that I framed for the mentioned use-case.

See this Sample App | DynamicMonthDropdown

Please refer to the attached .oml file


As per the João solution, there is a possibility to get duplicate month record appended in the Monthlist variable

 i.e. if the year diff between date2 and date1 is more than 1, the loop will append duplicate month value. For that, you can either define an additional logic to either terminate the loop or to prevent duplicay or else you can add a ListDistinct action after the loop to get the final unique month list from the MonthList variable.


Hope this helps you!


Kind regards,

Benjith Sam

RWALabDynamicMonthDDList.oml