I have string that contains “1.3” and I am checking with Date.TryParse method. It automatically converting into “1/3/2010”. How to handle this?


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.
Why
1.3freturns true onTryParse? Because theTryParsemethod take that as valid input. Probably, some of supported date formats separates token by dot. You may want to try method:DateTime.TryParse(String, IFormatProvider, DateTimeStyles, DateTime%)and as IFormatProvider supplyCultureInfo.createSpecificCulture("en-US or whatever you want").or
DateTime.TryParseExact, which allows you to supply specific format to parse the string into a DateTime object.