Safeena
Safeena

Reputation: 403

how can i convert time span to a double value

  TimeSpan totaldays = endtime.Subtract(starttime);
  double tdays = Convert.ToDouble(totaldays);

I m getting here error as

Unable to cast object of type 'System.TimeSpan' to type 'System.IConvertible'.

how can I get timespan value as a double type

Upvotes: 2

Views: 2235

Answers (2)

akhil kumar
akhil kumar

Reputation: 1618

being more simple

  double d=(endtime-starttime).totaldays;

worked for me.can reduce number of code lines.

Upvotes: 1

Russ Cam
Russ Cam

Reputation: 125488

Just need to use the TimeSpan.TotalDays property

TimeSpan totaldays = endtime.Subtract(starttime);
double tdays = totaldays.TotalDays;

Upvotes: 11

Related Questions