How to format the results of DateDiff ??

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,
Steve5140Asked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
PaulHewsConnect With a Mentor Commented:
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
 
Steve5140Author Commented:
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
 
PaulHewsCommented:
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
 
Steve5140Author Commented:
Very nice !!!  I was not aware of that class.

Thanks so very much.
0
All Courses

From novice to tech pro — start learning today.