This documentation is archived and is not being maintained.

Hour Function (Visual Basic)

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

Public Function Hour(ByVal TimeValue As DateTime) As Integer


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.

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 based on the locale settings of your code.

Dim someTime As Date 
Dim someHour As Integer
someTime = #4:35:17 PM#
someHour = Hour(someTime)
' someHour now contains 16.

Namespace: Microsoft.VisualBasic

Module: DateAndTime

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)