I am reading Excel worksheet data using C# and Microsoft.Office.Interop. The sheet contains some date values. When I am trying to read that value it is just giving the number (probably TimeSpan). I am having problem converting this number into DateTime.
Below is the code:
TimeSpan ts = TimeSpan.Parse(((Range)ws.Cells[4, 1]).Value2.ToString());
Where ws
is Excel.WorkSheet
.
Can anybody explain how should I convert this number (TimeSpan
) into DateTime
?
Thanks for sharing your valuable time.
You could do the following
double d = double.Parse(((Range)ws.Cells[4, 1]).Value2.ToString());
DateTime conv = DateTime.FromOADate(d);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With