Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to convert a string to DateTime

0 views
Skip to first unread message

ad

unread,
May 10, 2005, 3:28:38 AM5/10/05
to
I have a string
string dd="1992/12/03",

How to convert dd to DateTime type?


Maqsood Ahmed

unread,
May 10, 2005, 4:28:29 AM5/10/05
to
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

*** Sent via Developersdex http://www.developersdex.com ***

Maqsood Ahmed

unread,
May 10, 2005, 4:30:30 AM5/10/05
to
I am assuming that '12' is month and '03' is day...

Morten Wennevik

unread,
May 10, 2005, 4:35:20 AM5/10/05
to
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);

--
Happy coding!
Morten Wennevik [C# MVP]

ad

unread,
May 10, 2005, 6:04:47 AM5/10/05
to
Thank,
I find there are nothing different if we do't give the info parameter.
What dose this parameter do?


"Maqsood Ahmed" <maqsoo...@gawab.com>
???????:u08d$oTVFH...@TK2MSFTNGP14.phx.gbl...

Morten Wennevik

unread,
May 10, 2005, 6:50:49 AM5/10/05
to
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.

--

0 new messages