0

I want to convert string format date value to date format ("dd/MM/yyyy").

String EntryDate = "24052023"; 

DateTime ResultDate = Convert.ToDateTime(EntryDate);

DateTime ResultDate = Convert.ToDateTime(EntryDate).ToStringShortDate("dd/mm/yyyy");

But it's not working. Show error like string not valid datetime.

CodeCaster
  • 147,647
  • 23
  • 218
  • 272
arbabu
  • 17
  • 4

1 Answers1

1

Here is the solution:

string exp_date="24052023"; //string date

string ConvertExpDate = DateTime.ParseExact(exp_date,"ddMMyyyy", CultureInfo.InvariantCulture).ToString("dd'/'MM'/'yyyy");

//Result 
ConvertExpDate = 24/05/2023;

This code works.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
arbabu
  • 17
  • 4