How to convert a String to a DateTime in C#

Following example show how to convert a string into datatime type in C#, and this is very common to convert enter string into date. There are two methods one is Convert.ToDateTime(string) and second is DateTime.Parse methods that can be used for converting string into date.

string date = "07/09/2010";
DateTime dt = Convert.ToDateTime(date);
IFormatProvider culture = new System.Globalization.CultureInfo("en-us", true);
DateTime dt2 = DateTime.Parse(date, culture, System.Globalization.DateTimeStyles.AssumeLocal);

Note: when we convert string into date, Date strings are interpreted according to the current culture.suppose if you are using en-us culture then this is interpreted as month,date,year.and if you are using fr-FR culture then this is interpreted as date,month,year