tags:

views:

55

answers:

4

in C# , How can i build a DateTime object from a datetime present in a string object ( String strDate="11/11/2009")?

+5  A: 

Have a look at the DateTime.Parse or DateTime.ParseExact methods.

Simplest case:

var result = DateTime.Parse(str);
Konrad Rudolph
+1  A: 

Use DateTime.Parse

Pratik
+1  A: 

Using that string format will give you a lot of issues later, such as what is "03/04/2009"?

try using DateTime.ParseExact.

astander
+2  A: 

There's also DateTime.ParseExact which is also worth knowing about.

There's also TryParse and TryParseExact which do the same thing, but won't throw an exception if the date is not valid - will just return a bool.

AdaTheDev