I am trying to achieve the following expression for a value that has been exported from Excel.
This value could have been 9-12-2022 or 09-12-2022. The first input would trigger an error for the following expression: DateTime.ParseExact(variable, “d-MM-yyyy”,system.Globalization.CultureInfo.InvariantCulture)
Is it possible to assign the expression with ‘or’
DateTime.ParseExact(variable, “dd-MM-yyyy”,system.Globalization.CultureInfo.InvariantCulture) OR DateTime.ParseExact(variable, “d-MM-yyyy”,system.Globalization.CultureInfo.InvariantCulture)
If i try it, i receive expression error that the type of Assign with ‘OR’ is not possible for datetime variable.
Yes its possible to give multiple formats and also please try using .trim to make sure you remove any extra spaces. Below code will work with multiple formats you can add more formats as well
datevalue = DateTime.ParseExact(”Your date variable”, {"MM/dd/yyyy","MM/d/yyyy","M/dd/yyyy","M/d/yyyy",system.Globalization.culturalinfo.invariantculture, ,System.Globalization.DateTimeStyles.None)
Keep a message box and print the YourString and check the format there if the format in the expression and the message box differ add the additional format in the expression like
You can simply add the any number of date formats inside the {“”,“”} and the formats should be separated by comma
The above expression will look into array of string and choose the apt format as per the input string and convert them and return you the output of desired format.