?
Solved

C# Calculate the duration between two hours

Posted on 2012-09-21
5
Medium Priority
?
854 Views
Last Modified: 2012-09-21
I need to calculate the duration between two hours.  User is entering Start Time and End Time.  As an example:

Start Time = 12:00 PM
End Time = 2:00 PM

Duration = 2 Hrs

Any ideas?
0
Comment
Question by:CipherIS
  • 3
  • 2
5 Comments
 
LVL 22

Accepted Solution

by:
p_davis earned 2000 total points
ID: 38423279
EndTime.Subtract(StartTime); will return a timespan
0
 
LVL 1

Author Comment

by:CipherIS
ID: 38423282
how do i get the subtract?  They are both in text fields?
0
 
LVL 1

Author Comment

by:CipherIS
ID: 38423292
figured it out - thx
0
 
LVL 22

Expert Comment

by:p_davis
ID: 38423309
DateTime.Parse(StartTime); or try parse should give you what you want..

you will probably want to do some bad format testing before you try to parse but try parse will help you do that
0
 
LVL 22

Expert Comment

by:p_davis
ID: 38423310
DateTime.TryParse
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

807 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