Visual Basic Language Reference  

Hour Function

Returns an Integer value from 0 through 23 representing the hour of the day.

Public Function Hour(ByVal TimeValue As DateTime) As Integer

Parameter

TimeValue
Required. Date value from which you want to extract the hour.

You can also obtain the hour of the day by calling DatePart and specifying DateInterval.Hour for the Interval argument.

Example

This example uses the Hour function to obtain the hour from a specified time. In the development environment, the time literal is displayed in short time format using the locale settings of your code.

Dim MyTime As Date
Dim MyHour As Integer
MyTime = #4:35:17 PM#   ' Assign a time.
MyHour = Hour(MyTime)   ' MyHour contains 16.

See Also

Day Function | Minute Function | Now Property | Second Function | TimeOfDay Property | DatePart Function | System Namespace | DateTime Structure | ArgumentException Class | ArgumentOutOfRangeException Class