Monday, October 4, 2010

Visual Basic Date and Time Function : Hour , Minute , Second

Purpose : The Hour , Minute and Second function return an integer representing the hour, minute , second portions of a date value. The Hour function returns an integer that is between 0 (12:00am) and 23 (11:00pm) inclusive . The Minute and second function s return an integer between 0 and 59 representing the minute or second portion of the date value.

Syntax :
Hour ( expression )
Minute ( expression )
Second ( expression )

expression : Variant representing a date and time or a number that can be converted to a serial number

Option Explicit

Private Sub Form_Load()
Timer1.Interval = 1000
End Sub

Private Sub Timer1_Timer()
Dim NormalTime%
Dim DayTime$, Current$

Timer1.Interval = 1000
If Hour(Now) > 12 Then
DayTime$ = " PM "
NormalTime% = Hour(Now)
Else
DayTime$ = " AM "
NormalTime% = Hour(Now)
End If

Current$ = Str$(NormalTime) + " : "
Current$ = Current$ + Str$(Minute(Now)) + " : "
Current$ = Current$ + Str$(Second(Now))
Current$ = Current$ + DayTime$
Text1.Text = Current$
End Sub

No comments:

Post a Comment