My Code:
DateTime? birthDate = DateTime.Parse(filterDictionary.ContainsKey("DOB") ? filterDictionary["DOB"] : string.Empty);
I am getting Error Message as “String was not recognized as a valid DateTime.” How to solve this issue. Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The problem (at least one of them) is that you can’t parse an empty string to a
DateTime.Change your line of code to this to move the parsing only when you find the key, and return null instead of parsing when you don’t have it:
The other problem might be that your dictionary DOB value is actually not possible to convert to a
DateTime. If the above code does not work, please edit your question and post the value infilterDictionary["DOB"]when you get this error.