The VBA HOUR Function

Related Functions:
VBA Minute
VBA Second


The VBA Hour Function returns the hour component of a supplied time. The syntax of the function is:

Hour( Time )

VBA Hour Function Example

A simple example of the VBA Hour function is shown below:

' Extract the hour component from the time "17:56:33"
Const currTime = "17:56:33"
Dim hourNum As Integer
hourNum = Hour(currTime)
' The variable hourNum is now equal to 17.

After running the above VBA code, the variable hourNum holds the value 17, which is the hour component of the supplied time "17:56:33".

VBA Hour Function Error

If the VBA Hour function is supplied with a value that cannot be interpreted as a valid time, it will return the error:

Run-time error '13': Type mismatch

VBA Run Time Error 13 Message Box