How do I convert a string in ddMMyyyy format to a DateTime?
Try using DateTime.ParseExact
:
DateTime.ParseExact(yourDateString, "ddMMyyyy", CultureInfo.InvariantCulture);
See Parsing Date and Time and DateTime.ParseExact()
String dateString = "15072008";
String format = "ddMMyyyy";
try {
DateTime result = DateTime.ParseExact(dateString, format, CultureInfo.InvariantCulture);
Console.WriteLine("{0} converts to {1}.", dateString, result.ToString());
}
catch (FormatException) {
Console.WriteLine("{0} is not in the correct format.", dateString);
}
Prints:
15072008 converts to 7/15/2008 12:00:00 AM.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With