Saturday, 2 April 2011

How to assign a string value to datetime

string strDate = "21-03-2011";

DateTimeFormatInfo dtfi = new DateTimeFormatInfo();

dtfi.ShortDatePattern = "dd-MM-yyyy";

dtfi.DateSeparator = "-";

DateTime objDate = Convert.ToDateTime(strDate, dtfi);

MessageBox.Show(objDate.ToShortDateString());

No comments:

Post a Comment