We help IT Professionals succeed at work.
Get Started

Calculating Number of Seconds Passed Using VB .Net

341 Views
Last Modified: 2012-05-12
I am trying to identify how many seconds have passed since an action occurred.  For example, I receive a message and I set a variable when it is received.  When 45 seconds have passed, I want to perform some other action.

The problem is that when I use my calculation, the seconds go from 0-59, and then start back at 0.  I am trying to find a calculation that will show me a result of 60 or more seconds.  Below is an example of what I'm currently doing:

        lastMessageReceived = DateTime.Now

        Threading.Thread.Sleep(65000)

        If DateTime.Now.Subtract(lastMessageReceived).Seconds > 45 Then

        End If

When I do this, the result I get when calculating the difference in lastMessageReceived and DateTime.Now is 15 seconds instead of 65 seconds.

Is there another calculation that will show me total seconds, and not reset after it reaches 59?
Comment
Watch Question
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015
Commented:
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE