Sujeet Raman

Sujeet Raman

  • 752
  • 927
  • 354.2k

How to convert m/d/yyyy string to mm/dd/yyyy to bind excel ?

Aug 27 2021 5:19 AM

Hi,

I have a string coming from excel as "8/3/1989" (m/d/yyyy) in below code.I need to convert it in to 08/03/1989 .In excel coloumn the format is text.I alwas getting error after every conversion like input string is not in correct format in. below code I am using

string effdate= xlWorksheet.Cells[i, 8].Value.ToString();
DateTime dt = DateTime.Parse(effdate);
xlWorksheet.Cells[i, 8] = dt.ToString();
xlWorksheet.Cells[i, 8].NumberFormat = "MM/DD/YYYY";

Answers (3)