Wednesday, August 1, 2012

How to convert a string date value to DateTime when it complex



    Sometimes we accept Date value in textbox as a string format in "dd/MM/yyyy" but our database field contain the DateTime datatype. The complex situation comes that the string does not convert to DateTime easily. Here a single line which will convert it surely

  BnkDt.Text ="15/08/2012" //"dd/Mm/yyyy" format
 IFormatProvider Culture = new System.Globalization.CultureInfo("fr-FR", true);
 DateTime dt = DateTime.Parse(BnkDt.Text, Culture, System.Globalization.DateTimeStyles.AssumeLocal);

No comments:

Post a Comment