Hi all,
Wondering how to validate a date through coding. The case is I have 3 fields : Days, Month, and Year, when it put together this will be date, but of course it needs to make sense, especially for Leap year. For example 29 February 2021 is not make sense.
For the normal month I can make an If condition saying if it is April or June, and the date is > 30 it is incorrect, but Leap year, is there any special function or I should create further validation just to acknowledge it is Leap Year and 29 February is wrong.
I tried a simple way, by using MKDATE function combine with Try and Catch, but unfortunately this function does not give error if the calendar date is wrong, instead it is automatically correct it.
The code is like this :
try
{
TransDate checkDate = mkDate(enum2int(this.Days), enum2int(this.Months), (this.Years));
}
catch
{
ret = checkFailed("Wrong date");
}
When I choose Days = 29, Month = FEB, Year = 2021, it didn't falls to error catch instead in debug I saw the checkDate became 28/2/2021.
It is great function, however.
Thanks