VBA Hour

Hour Function Description

The VBA Hour function returns the hour for the provided time (Date variable). Values range from 0 to 23.

VBA Hour Syntax

The syntax for the Hour function in VBA is:

1
Hour( time )

Parameters

time
The time (Date) value for which the hours are to be returned. This can be a Date variable or string expressing date/time e.g. “20:10”.

Example Usage

The Hour function can be used in VBA code. Let’s look at some VBA Hour function examples:

1
2
3
4
5
6
7
8
9
10
Hour "20:10"
'Result: 20
 
Hour #8:20:00 PM#
'Result: 20
 
Dim d as Date
d = #9:02:00 PM#
Debug.Print Hour(d)
'Result: 9