in C# , How can i build a DateTime object from a datetime present in a string object ( String strDate="11/11/2009")?
views:
55answers:
4
+5
A:
Have a look at the DateTime.Parse
or DateTime.ParseExact
methods.
Simplest case:
var result = DateTime.Parse(str);
Konrad Rudolph
2009-11-21 11:22:07
+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
2009-11-21 11:23:58
+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
2009-11-21 11:25:14