I have column in Excel which has the number of hours in Time Format. For example- 2:00, 3:00 My job is to get those numbers from excel and put them into SQL. so what is the data type that I need to used to get those values in c# code. I have tried a couple of ways! It says - "Cannot convert Double to string" or "Cannot convert Double to TimeSpan" Please let me know what do I need to do.
Thanks
Excel only uses effectively 2 data types when data is read from C# - numbers and strings. Dates are usually passed as numbers which represent a number of days (including fractional days to represent time) since 1/1/1900, and can easily be converted to
DateTime
using theFromOADate
method. You can then use theTimeOfDay
property to get just the time as aTimeSpan
object, which has aTotalHours
property that represents the number of hours (and fractional hours) the time span represents.Another method would be to take the fractional part of the number and multiply it by 24.