Return to VBA Code Examples

VBA Hour Function

Written by

Editorial Team

Reviewed by

Steve Rynearson

Last updated on July 19, 2021

Hour Description

Returns the hours (a number from 0 to 23) from a time value.

Simple Hour Examples

Here is a simple Hour example:

Sub Hour_Example()
        MsgBox Hour(#8/14/2019 5:05:00 AM#)
End Sub

This will return 5.

Hour Syntax

In the VBA Editor, you can type¬† “Hour(” to see the syntax for the Hour Function:

The Hour function contains an argument:

Time: A valid time.

Examples of Excel VBA Hour Function

MsgBox Hour("8/14/2019 15:05:00")

Result: 15

MsgBox Hour(#8/14/2019 5:05:00 PM#)

Result: 17

MsgBox Hour("6:05:00")

Result: 6

MsgBox Hour(Now)

Result will be the hour of the current system time.

VBA Coding Made Easy

Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users! vba save as

Learn More!

VBA Code Examples Add-in

Easily access all of the code examples found on our site.

Simply navigate to the menu, click, and the code will be inserted directly into your module. .xlam add-in.

(No installation required!)

Free Download

Return to VBA Code Examples