Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

converting string to timespan asp.net

Posted on 2006-06-05
2
Medium Priority
?
1,523 Views
Last Modified: 2010-05-19
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?  
0
Comment
Question by:tentavarious
2 Comments
 
LVL 9

Expert Comment

by:stengelj
ID: 16836890
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
 
LVL 16

Accepted Solution

by:
Edwin_C earned 500 total points
ID: 16839224
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

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month11 days, 20 hours left to enroll

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question