I want to convert this string "12092014" into DateTime
object as 12 september
2014.
Asked
Active
Viewed 66 times
-3

Imran Ali
- 87
- 3
- 11
-
Parse it using the `DateTime.Parse` or `TryParse` method. – DevEstacion Nov 27 '14 at 07:03
-
possible duplicate of [Parse Simple DateTime](http://stackoverflow.com/questions/3551283/parse-simple-datetime) – DevEstacion Nov 27 '14 at 07:05
1 Answers
1
If ddMMyyyy
is a standard date and time format of your CurrentCulture
, you can use DateTime.Parse
directly;
var date = DateTime.Parse("12092014");
If it is not, you can use custom date and time format with DateTime.TryParseExact
method like;
string s = "12092014";
DateTime dt;
if(DateTime.TryParseExact(s, "ddMMyyyy",
CultureInfo.InvariantCulture,
DateTimeStyles.None, out dt))
{
Console.WriteLine(dt);
}

Soner Gönül
- 97,193
- 102
- 206
- 364
-
1I would strongly recommend using `TryParseExact` anyway - it says exactly what the OP is expecting. – Jon Skeet Nov 27 '14 at 07:04