Validate date entered by user in Dd-mm-yyyy Format

The user will be entering the date in dd-mm-yyyy format and i need to check whether the date entered is a valid date. I converted the user input which was in string format to dateTime format and assigned to a variable date_format of data type dateTime. My issue is that the input given by user is stored in the date_format variable in mm:dd:yyyy format due to which all dates entered by the user starting from 13th date of a month are showing as an error. I tried to find many discussions on this but still not able to find a solution.
Thank you

I didnt get all but the format for Month is MM

If MyDateStr is the user-input string which is meant to be formatted as dd-MM-yyyy (I assume you want dd-MM-yyyy, since dd-mm-yyyy will put the minutes in the middle), use TryParseExact to confirm if the date has a valid format.

Assign your datetime variable MyDatetime with Datetime.TryParseExact(MyDateStr, "dd-MM-yyyy", System.Globalization.CultureInfo.InvariantCulture, MyDatetime), and capture the result in IsValidDate. I’ve attached a workflow showing how to do this. (1,8 Ko)

Wouldn’t “IsValidDate” work just as is from the string? I’ve done some tests with this for our own purpose and didn’t need to have the parsing.

It does need the parse method. If you set the boolean to the date variable, that will only set it to True if the value is not set to Nothing.

I saw your workflow and I understood and it is running in my system in your workflow but when i try to use your code in my workflow similar to that of yours, it says “DateTimeStyles is not declared. It may be inaccessible due to its protection level” What do I do for this??
Thanks @Anthony_Humphries

Change it to System.Globalization.DatetimeStyles.None, and it’ll work. It sounds like a namespace problem.

Still it doesn’t work. I dont understand how the same code is working in your workflow in my system :thinking:
This is the error it shows! @Anthony_Humphries 15857745752932669060901845199813|666x500

You’re missing the 3rd argument, System.Globalization.CultureInfo.InvariantCulture. It should be:

DateTime.TryParseExact(Date_check, "dd-MM'yyyy", System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, Date_Data_Type).

1 Like

@Anthony_Humphries Thanks a lot. I got confused when you told me to change. Anyways it is working and thank you very much

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.