-2

How can i format/convert the date "20200415" to 2020-04-15? string date = "20200415";

the output should 2020-04-15

1 Answers1

0

I wouldn't make string manipulation - my approach with parsing the date with a formated output in a second step:

string date = "20200415";
DateTime dtTemp = DateTime.ParseExact(date, "yyyyMMdd", null);
string result = dtTemp.ToString("yyyy-MM-dd");
fubo
  • 44,811
  • 17
  • 103
  • 137