Friday, August 28, 2009

How to convert a string to a date

How to convert a string to a date

Finding out how to convert one type to another in .NET is tricky. Here is the answer to converting a string to a DateTime type. Notice that any of the string formats work -- how nice!

//string strDate="2002-10-03";
//string strDate="10/04/2002";
string strDate="10/05";
DateTime dt = (DateTime)(TypeDescriptor.GetConverter(new DateTime(1990,5,6)).ConvertFrom(strDate));
Response.Write("

" + dt.DayOfWeek);




View Full Details...............................

No comments:

Post a Comment