I am extracting data from an Excel spreadsheet using interop in C# and I have a small problem that I cant think of an answer for.
When I extract the data for date cell using this code:
string _date = xlWorksheet.get_Range("B3", "B3").Value2.ToString().Trim();
I get a value of 40694 which wont go directly in to SQL using my insert statemwnt.
I have also tried:
DateTime _date = Convert.ToDateTime(xlWorksheet.get_Range("B3", "B3").Value2.ToString().Trim());
But that comes back with an error saying that it cant convert it.
Can anyone advise me on how to do it?
Use
DateTime.FromOADate()Using your example:
DateTime _date = DateTime.FromOADate(Double.Parse(xlWorksheet.get_Range("B3", "B3").Value2))