VBA - Hour Function


Advertisements

The Hour Function returns a number between 0 and 23 that represents the hour of the day for the specified time stamp.

Syntax

Hour(time) 

Example

Add a button and add the following function.

Private Sub Constant_demo_Click()
   msgbox("Line 1: " & Hour("3:13:45 PM"))
   msgbox("Line 2: " & Hour("23:13:45"))
   msgbox("Line 3: " & Hour("2:20 PM"))
End Sub

When you execute the above function, it produces the following output.

Line 1: 15
Line 2: 23
Line 3: 14 
vba_date_time.htm
Advertisements