Solved

How to format the results of DateDiff ??

Posted on 2012-04-06
4
294 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
  • 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

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

Suggested Solutions

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

809 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