Reputation: 93
Okay, I hate just posting a question with no code, but I literally have no idea how to get started other than to user a Timer
. I have a Visual Basics program which works with an SQL Table. I'd like to have a label which shows the user how 'old' their display of the table is.
Each time they edit or refresh the table a label is refreshed with a current time stamp. Formatted as 03:19;27.
However, I'd like to show how many seconds or even just minutes the table was last updated.
For example: 'Last updated: 22 Seconds Ago' OR 'Last Updated: Less Than A Minute Ago'.
How could I do this?
Upvotes: 1
Views: 788
Reputation: 43743
The TimeSpan
object provides all of the properties you need to format the message however you want. The formatting options in it's ToString
method may also be very helpful to you. To get a TimeSpan
object, you can simply subtract one Date
from another, like this:
Dim span As TimeSpan = lastQueryDate - Date.Now
Dim message As String = String.Format("Last Updated: {0} Seconds Ago", span.TotalSeconds)
Or, if you want to use a Stopwatch
object, you could get the span of time since the stopwatch was started by accessing its Elapsed
property, which is also a TimeSpan
object.
Upvotes: 2