Question Countup timer from a specified date

sgwrist

New member
Joined
Feb 25, 2009
Messages
2
Location
Kentucky
Programming Experience
5-10
What I'm trying to accomplish is a timer (I know the concept of stopwatch/timers) that counts up in seconds from a specified date. The date is not user input, it can be included in the code.. I just want it to display on a form and I'll take care of the graphics :p Can someone help me with the actual object or how to actually count up from the specified date:

The program will run like this.. when you open the file it will show how many days its been since the specified date and continue to count up in seconds.

Any help is appreciated.

:D :D :D
 
Are you saying that you want to know how to display the difference in time intervals on a form or user control?

If so, you need to use the DateDiff function as follows, where the incrementing counter is displayed on a form Label (triggered to update by the timer):

VB.NET:
Public Class Form1

    Private StartTime As Date = Date.Now

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
        Label1.Text = DateDiff(DateInterval.Second, StartTime, Date.Now).ToString
    End Sub

End Class
 
Countup timer

Basically lets say you had a date SEPTEMBER 18th 2008, no user control (except to exit lol) but anyways when it loads up, on a label it will display how many days it has been since SEPTEMBER 18th 2008 and it will continue to count by seconds updating as long as the form is open..
| |
| 161 Days 12 hours 34 min 18 sec |
| Since 9/18/08 !!!!!! |
| |
| |
| |EXIT| |

This is kinda how it would look
and yeah I know it is really that simple, but I'm new to VB
p.s. dont worry about coding the exit button rofl
 
Last edited:
Enable the Timer to Interval 1000 (1 second), add this code to the Tick event handler:
VB.NET:
Dim startdate As Date = New Date(2008, 9, 18)
Dim datediff As TimeSpan = Date.Now - startdate
Me.Label1.Text = String.Format("{0} Days {1} hours {2} min {3} sec" & vbNewLine & "Since {4} !!!!!!", _
                               datediff.Days, _
                               datediff.Hours, _
                               datediff.Minutes, _
                               datediff.Seconds, _
                               startdate.ToShortDateString)
 
Back
Top