I have a string variable lastUpdated(Dec 12, 2023 4:02 PM) that needs to be converted to Date Time format (dd/mm/yyy/hh:mm).
I tried with method DateTime.ParseExact(lastUpdated, “dd-MM-yyyy”,System.Globalization.CultureInfo.InvariantCulture) but getting error: Assign: String was not recognized as a valid DateTime.
Should I use different method in order to achieve convertion to Date Time?
You are getting the error because the format given in the string variable and the format in the DateTime conversion does not match. Check out the syntaxes given below. This will provide you the correct output.