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
C#
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";
Ganesan CRank #369 · 6.8K reputationPosted Aug 28, 2021, 6:47 AM EDT
Hi, Convert to required format and assign date with correct format in excel.
xlWorksheet.Cells[i, 8] = dt.ToString("MM-dd-yyyy");Abhishek ChadhaRank #402 · 6.2K reputationPosted Aug 27, 2021, 1:39 AM EDT
https://www.c-sharpcorner.com/code/1566/convert-date-time-in-c-sharp.aspx
Meena Bisht139 reputationPosted Aug 28, 2021, 4:03 AM EDT