How to convert a string to DateTime

  • Thread starter Thread starter ad
  • Start date Start date
Hello,
System.Globalization.DateTimeFormatInfo info = new
System.Globalization.DateTimeFormatInfo();
info.ShortDatePattern = "yyyy/MM/dd";
DateTime dt = DateTime.Parse(dd,info);

HTH, Cheers
Maqsood Ahmed [MCP,C#]
Kolachi Advanced Technologies
http://www.kolachi.net
 
Hi ad,

Do as Maqsood Ahmed told you, or use DateTime.ParseExact

string dd="1992/12/03";
DateTime dt = DateTime.ParseExact(dd, "yyyy/MM/dd", CultureInfo.InvariantCulture);
 
Thank,
I find there are nothing different if we do't give the info parameter.
What dose this parameter do?
 
You didn't specify what local you are using.

You can use DateTime.Parse(string) if the date is formatted in the default way as defined by your windows version. For me your date would caused an exception as DateTime on my system would have expected
03.12.1992.

Our solutions are locale independent and should work no matter what date format is default.

Thank,
I find there are nothing different if we do't give the info parameter.
What dose this parameter do?


Maqsood Ahmed said:
Hello,
System.Globalization.DateTimeFormatInfo info = new
System.Globalization.DateTimeFormatInfo();
info.ShortDatePattern = "yyyy/MM/dd";
DateTime dt = DateTime.Parse(dd,info);

HTH, Cheers
Maqsood Ahmed [MCP,C#]
Kolachi Advanced Technologies
http://www.kolachi.net
 
Back
Top