Solved

How to format the results of DateDiff ??

Posted on 2012-04-06
4
296 Views
Last Modified: 2012-04-06
Hello Experts,

I must be brain dead today because I can't figure out what must be a very simple problem.

I have an app that requires a timer to report elapsed time.

 I have a start button and a stop button

I find the difference like this:

lblElapsedTime.Text = DateDiff(DateInterval.Second, Date1, Date2).ToString


However, I want lblElapsedTime.text to be in the HH:MM:SS format.

Instead the label counts up in seconds.  after 60 seconds it just keeps counting up.  427 seconds doesn't mean anyting to users they want to know HH:MM:SS

How can I format the results ?

Thanks,
0
Comment
Question by:Steve5140
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 38

Accepted Solution

by:
PaulHews earned 500 total points
ID: 37816095
Rather than use DateDiff, use Subtract, which returns a timespan which will give you a nicer formatting when calling tostring.

 lblElapsedTime.Text = Date2.Subtract(Date1).ToString
0
 

Author Comment

by:Steve5140
ID: 37816159
Paul - That works thank you very much !!

Now I need to add a "Pause" function to the timer.

Can you recommend any built in functions to help with that ?

(I'll give you the points anyway - you answered the question I asked, thank you very much.)
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 37816193
You might look at using the stopwatch class, which is useful for capturing elapsed time.  Start and Stop would effectively give you a "Pause" functionality.
0
 

Author Comment

by:Steve5140
ID: 37816220
Very nice !!!  I was not aware of that class.

Thanks so very much.
0

Featured Post

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…

752 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