converting string to timespan asp.net

Hello experts I have a value stored in a database as a string like so: hh:mm:ss  for example 00:34:32 which is 34 minutes and 32 seconds.  I need to convert this into a hours like so .5 hours.  How can I accomplish this?  
tentavariousAsked:
Who is Participating?
 
Edwin_CCommented:
Here is a more generic solution

string s = "00:34:32";  //your input is a string, right?
string[] strArray = s.Split(new char[] {':'});  //separate the string into three parts
TimeSpan ts = new TimeSpan(
      Convert.ToInt32(strArray[0]),
      Convert.ToInt32(strArray[1]),
      Convert.ToInt32(strArray[2]));  //create the time span
double nHour = ts.TotalHours;  //number of hours in double
nHour = Math.Floor(nHour/0.5) * 0.5;  //do this if you want to round down to half hour

Hope that helps
0
 
stengeljCommented:
Try this...
=============================
Dim myTime As DateTime = "#00:34:32#"
Dim myAltTime As String = CStr(Math.Round(CInt(myTime.Minute) / 60, 1)) & " hour(s)")
Response.Write("myAltTime")
=============================


It should output "0.5 Hour(s)"
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.