How to convert string to DateTime using C#

  • Thread starter Thread starter David
  • Start date Start date
D

David

Hi, all,
I need to convert a string like "4-Sep-03" to a DateTime type using C#. I
know I need to use Convert or DateTime.Parse(). I also can find a lot of
samples for the conversion like "04/09/2003". However, I can not find any
examples I need. I am very appreciated if anyone can post a sample code for
my problem. Thank you very much in advance.

Best Regards,

David
 
Yes you should use the DateTime.Parse method e.g.:-
string datestring = "4-Sep-03";

DateTime parseddate = DateTime.Parse(datestring);

MessageBox.Show(parseddate.ToString());



Peter
 
Peter,
Thank you very much for your response. I found the problem
in my code. I passed the wrong string to convert date. No
wonder I couldn't get the correct result.

Thanks,

David
 
Back
Top