Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How to format the results of DateDiff ??

Posted on 2012-04-06
4
Medium Priority
?
299 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 2000 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

Enroll in September's Course of the Month

This month’s featured course covers 16 hours of training in installation, management, and deployment of VMware vSphere virtualization environments. It's free for Premium Members, Team Accounts, and Qualified Experts!

Question has a verified solution.

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

This article explains how to create and use a custom WaterMark textbox class.  The custom WaterMark textbox class allows you to set the WaterMark Background Color and WaterMark text at design time.   IMAGE OF WATERMARKS STEPS Create VB …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

688 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