We help IT Professionals succeed at work.

Calculating Number of Seconds Passed Using VB .Net

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:
Use TotalSeconds, not Seconds.

Author

Commented:
That works.  Thanks!
CERTIFIED EXPERT
Most Valuable Expert 2011
Top Expert 2015

Commented:
NP. Glad to help  = )

Explore More ContentExplore courses, solutions, and other research materials related to this topic.