Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, and 2013. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Determining the Hour of the Day.

Determining the Hour of the Day

Written by Allen Wyatt (last updated December 16, 2021)
This tip applies to Excel 2007, 2010, and 2013


1

If you are writing macros for Excel, you may have a need to determine the hour represented by a particular date and time value. For instance, you might want to know the hour of the day in which the macro is running. You can ascertain this information by using the HOUR function, as follows:

iThisHour = Hour(Now())

When executed, iThisHour will be equal to the current hour number, which ranges from 0 to 23. Notice that this example uses the Now() function. If you want to determine the hour number for a different date and time value, simply substitute that value in place of the Now() function.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9009) applies to Microsoft Excel 2007, 2010, and 2013. You can find a version of this tip for the older menu interface of Excel here: Determining the Hour of the Day.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Printing Formatted Comments

When you print your worksheet, you may want Excel to include your comments or notes as they appear on the screen. Here's ...

Discover More

Keeping Fields and Text Together

You can use fields for a wide variety of purposes in your documents. If you want to make sure that a field and the text ...

Discover More

Printing Odd or Even Pages

You can instruct Word, when printing your document, to print only the odd- or even-numbered pages. This tip explains how ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Unprotecting Groups of Worksheets

Unprotecting a single worksheet is relatively easy. Unprotecting a whole lot of worksheets is harder. Here's how you can ...

Discover More

Enforcing Moving Cells Up

When you design your worksheets, you probably want users to interact with those worksheets in specific ways. What ...

Discover More

Generating a Keyword Occurrence List

Need to pull a list of words from a range of cells? This tip shows how easy you can perform the task using a macro.

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is one less than 9?

2013-10-15 10:07:47

Bryan

In VBA you don't need to include the parentheses if there are no arguments, so Hour(Now) is the same as Hour(Now()). There's no harm in leaving them, other than you might be tempted to put in an argument where there is none.

In contrast, in Excel you must use the parentheses, as this is how Excel knows you are referencing a function. =HOUR(NOW()) will give you the correct result, whereas =HOUR(NOW) will display the #NAME? Error.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.