Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting Timespan to DateTime in C#

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.

like image 392
IrfanRaza Avatar asked Jan 25 '11 07:01

IrfanRaza


1 Answers

You could do the following

double d = double.Parse(((Range)ws.Cells[4, 1]).Value2.ToString());

DateTime conv = DateTime.FromOADate(d);
like image 97
Dimi Takis Avatar answered Sep 28 '22 17:09

Dimi Takis