Solved

How to format the results of DateDiff ??

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now