Hi guys

I want to convert the following string to datetime format but not sure how to go from here
Any help is appreciated.

Thanks!

2013063018 to 30/06/2013 18:00

string date = strFields[0];
//string format = "ddMMyyyHH";
DateTime dt = DateTime.ParseExact(date, "dd/mm/yyyy hh:ss", CultureInfo.InvariantCulture);

Recommended Answers

All 5 Replies

DateTime dt;

DateTime.TryParseExact("2013063018", "yyyyMMddHH", CultureInfo.InvariantCulture, DateTimeStyles.None, out dt);

Hi thanks for the help.

But wouldn't the output still be: 2013063018 ?

No, the output is a DateTime structure. How it stores the information internally isn't important, how you display it is up to you.

Can you show output source code?

Console.WriteLine(dt.ToString()) You can place an output format in the ToString() call. This is specified the same way that you did it for the input.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.