Hour Function
Returns a whole number between 0 and 23, inclusive, representing the hour of the day.
Syntax
Hour(time)
Arguments:
Time: Required. Any expression that can represent a time.
Supported Date Formats:
MM-DD-YYYY
MM/DD/YYYY
DD-MM-YYYY
DD/MM/YYYY
YYYY-MM-DD
YYYY/MM/DD
Supported Time Format:
hh:mm:ss
Remarks
The following example uses the Hour function to obtain the hour from the current time:
Example 1:
Dim MyTime, MyHour
MyTime = Now
MyHour = Hour(MyTime)
'Output: current hour.
Example 2:
Dim MyTime, MyHour
MyTime = "14:30:00" ' Specific time value.
MyHour = Hour(MyTime)
'Output: 14
Example 3:
Dim MyDateTime, MyHour
MyDateTime = "21/01/2025 18:45:00" ' Date-Time value.
MyHour = Hour(MyDateTime)
'Output: 18
Example 4:
Dim MyDateTime, MyHour
MyDateTime = DateAdd("h", 5, Now)
MyHour = Hour(MyDateTime)
'Output: If current time is 1 PM, then it returns 18