TOP

VBA Function: Hour

YouLibreCalc for Excel logo

Description

The VBA Hour function returns an integer that corresponds to the time of the specified date or time.


Hour Syntax

Hour(date_hour)

VBA Hour Example

Using the Hour function to get the appropriate time information:

Sub HourExample1()
    
      myHour = #6:36:45PM#
    
      MsgBox Hour(myHour) 'Returns: 18

End Sub

Or by date and time (for the same result):

Sub HourExample2()
    
      myDate = #10/31/2020 6:36:45 PM#
    
      MsgBox Hour(myDate) 'Returns: 18

End Sub

This function also accepts dates and times in text format:

Sub HourExample3()
    
      myDate = "10/31/2020 18:36:45"
    
      MsgBox Hour(myDate) 'Returns: 18

End Sub
The function returns the minutes of the current time: MINUTE
Function that returns the seconds of the current time: SECOND