0% found this document useful (0 votes)
80 views4 pages

Timer Codes

The document discusses four options for displaying the date and time on a label in Visual Basic applications. Option 1 and 2 are for VB 2008, while Option 3 and 4 are for VB 6. Each option demonstrates code to write the date and time to a label on form load and on a timer tick event using functions like WeekdayName, DateValue, and TimeValue to retrieve parts of the current date and time. The document also provides examples of calculating time differences in hours, minutes and seconds by using the DateDiff function in VB and constructing times from hours, minutes and seconds using the TimeSerial function.

Uploaded by

Ichigo Kurusaki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
80 views4 pages

Timer Codes

The document discusses four options for displaying the date and time on a label in Visual Basic applications. Option 1 and 2 are for VB 2008, while Option 3 and 4 are for VB 6. Each option demonstrates code to write the date and time to a label on form load and on a timer tick event using functions like WeekdayName, DateValue, and TimeValue to retrieve parts of the current date and time. The document also provides examples of calculating time differences in hours, minutes and seconds by using the DateDiff function in VB and constructing times from hours, minutes and seconds using the TimeSerial function.

Uploaded by

Ichigo Kurusaki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 4

Re : Date and Time on Label

Option 1 for VB 2008

Put this in the form_load event


Label1.Text = "Date : " + WeekdayName(Weekday(Now)) + " " + DateValue(Now)
Label2.Text = "Time : " + TimeValue(Now)

Put this in the timer1_tick event


Label1.Text = "Date : " + WeekdayName(Weekday(Now)) + " " + DateValue(Now)
Label2.Text = "Time : " + TimeValue(Now)

Option 2 for VB 2008

Put this in the form_load event


Label1.Text = "Date : " + WeekdayName(Weekday(Now)) + " " + DateValue(Now) + " "
+ "Time : " + TimeValue(Now)

Put this in the timer1_tick event


Label1.Text = "Date : " + WeekdayName(Weekday(Now)) + " " + DateValue(Now) + " "
+ "Time : " + TimeValue(Now)

Option 1 for VB 6

Put this in the form_load event


Label1.Caption = "Date : " + WeekdayName(Weekday(Now)) + " " + DateValue(Now)
Label2.Caption = "Time : " + TimeValue(Now)

Put this in the timer1_timer event


Label1.Caption = "Date : " + WeekdayName(Weekday(Now)) + " " + DateValue(Now)
Label2.Caption = "Time : " + TimeValue(Now)

Option 2 for VB 6

Put this in the form_load event


Label1.Caption = "Date : " + WeekdayName(Weekday(Now)) + " " + DateValue(Now) +
" " + "Time : " + TimeValue(Now)

Put this in the timer1_timer event


Label1.Caption = "Date : " + WeekdayName(Weekday(Now)) + " " + DateValue(Now) +
" " + "Time : " + TimeValue(Now)
Time Calculations

Time Calculation

If you have two text boxes with times in them

Dim d1, d2 as string


Dim hourz, minz, secz as Integer

d1=trim(Text1.text)
d1=trim(Text2.text)

' Find Hour Difference


hourz = DateDiff("h", d1, d2)

' Find Minutes Difference


minz = DateDiff("n", d1, d2)

'Find Seconds Difference


secz = DateDiff("s", d1, d2)

Debug.Print hourz
Debug.Print minz
Debug.Print secz

time difference

hi guys
how to solve the time difference in hours and minutes using sql...?
example given

time_in = 07:30 AM
time_out = 5:02 PM

Time Serial

Dim intHour As Integer

Dim intMinute As Integer

Dim intSecond As Integer

Dim dtmNewTime As Date


intHour = 11

intMinute = 34

intSecond = 44

dtmNewTime = TimeSerial(intHour, intMinute, intSecond)

'returns 11:34:44 (AM)

Function Description
Hour Returns an integer specifying a whole number between 0 and
23 representing the hour of the day.

Example:

intHour = Hour(Now) ' intHour = 21 (for 9 PM)

Minute Returns an integer specifying a whole number between 0 and


59 representing the minute of the hour.

Example:

intMinute = Minute(Now) ' intMinute = 15

Second Returns an integer specifying a whole number between 0 and


59 representing the second of the minute.
Example:

intSecond = Second(Now) ' intSecond = 20

You might also like