0

I have a string: "20180830" which represents 30 august 2018 I want to go to string: "30/08/2018" So that I can do: DateTime parsedDate = DateTime.Parse("30/08/2018"); and have a DateTime instead of a string,

Tried everything but didn't succeed. Needs some help.

Pieter W
  • 13
  • 2

1 Answers1

0

You can use the DateTime.ParseExact-Method to solve your problem. Therefore you need to specify the exact format which would be yyyyMMdd in your case. Also the documentation suggests to use CultureInfo.InvariantCulture.

The following code...

DateTime datetime = DateTime.ParseExact("20180830", "yyyyMMdd", CultureInfo.InvariantCulture);

...should do the trick ;-)

Markus Safar
  • 6,324
  • 5
  • 28
  • 44