Hi All,
Currently I have 1 request to let user select/input an integer for "Day" and select a month from a combo box in a form. What I would like to ask is that, how can I get a flow to check or validate the "Day" value entered by user is within the valid day/date range for the given month??
E.g. If user select January, they can only enter day 1 to day 31; February, they can enter only 1 to 28 (29 depends on leap year); April, they can enter 1 to 30.
Hello @J u n i o r,
Just a few questions to understand the use case here.
Will the Year always default to the current year? If not, then user would need to choose the year too right?
Assuming the year is always the current year, then do you have the option to design the flow to be the other way around - where user chooses the Month first, and then chooses the day from either a dropdown (no validation needed in this case) or enters the day manually?
Regards,
AJ
Hi AJ,
For our scenario we don't need to save/maintain the Year in the form. And yes, I was actually thinking about letting user to choose the month first, then the OnChange action will take care of the values to be shown in the Day area. The concern is just that, I am not sure how to get the correct Day available for the month during the action is executed.
So if you are open to the option of having user select the month first and then day, the Date Selector asset may help. I have not used it before so I tried it out and verified that days are displayed correctly based on the Year and Month selected. The year could be defaulted to current year so user does not have to choose it. So at least you have an option among other possible solutions.
Hi Aj,
Just adding extra info, actually both Day and Month are separated fields in the form, does that still applicable to the component??
Hi Junior,
For getting the last day of a Month of current year you can use this (NextMonth = Month + 1):
Day(AddDays( BuildDateTime(TextToDate("#"+ Year(CurrDateTime()) + "-" + NextMonth + "-1#"),TextToTime("#00:00:00#")) ,-1))
Cheers,
Khuong
Hi Khuong,
Thanks for your suggestion, but I couldn't get what are the expressions saying, maybe can you brief me about ??
The function above is to get last day of a month.
In your case, assume that user select Month = 2, then you need to know what is the last day of Feb of current year (2021) right?
In the function:
- BuildDateTime should return: 2021-03-01 00:00:00 ( the first day of next month)
- AddDays(#2021-03-01 00:00:00#, -1): Get 1 day before the day means 2021-02-28
- Day() function to get day of a date => Day(#2021-02-28#) will return 28
Hope this clear,
Are you getting the values of Months from a static entity? If so add an extra attribute and store the total number of days in there. Only when it is February check the year and divide it by 4 to know whether its a leap year. If its a leap year add 1 to the total number of days.
Hope this works
Thanks,
Shree
just provide the day in the maximum upper bound (say it to 31) and the user is identified to be error using this built-in function:
regards