Reputation: 218732
in C# , How can i build a DateTime object from a datetime present in a string object ( String strDate="11/11/2009")?
Upvotes: 1
Views: 131
Reputation: 147244
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.
Upvotes: 3
Reputation: 166396
Using that string format will give you a lot of issues later, such as what is "03/04/2009"?
try using DateTime.ParseExact.
Upvotes: 1
Reputation: 545608
Have a look at the DateTime.Parse
or DateTime.ParseExact
methods.
Simplest case:
var result = DateTime.Parse(str);
Upvotes: 6