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

Determining the Hour of the Day

Written by Allen Wyatt (last updated August 1, 2026)

1

If you are writing macros in VBA, 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 WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (11880) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, 2021, 2024, and Word in Microsoft 365. You can find a version of this tip for the older menu interface of Word 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

Setting an Alarm

By using the alarm capabilities of Windows, you can make sure you never miss another important time again. This tip shows ...

Discover More

Moving Master and Subdocuments

If you need to move master documents or subdocuments from one place to another on your computer, you have to keep in mind ...

Discover More

Displaying Shortcut Keys in ScreenTips

ScreenTips can appear with or without shortcut keys displayed in them. Here's how to control whether they appear or not.

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 365 applications with VBA programming. Written in clear terms and understandable language, the book includes systematic tutorials and contains both intermediate and advanced content for experienced VB developers. Designed to be comprehensive, the book addresses not just one Office application, but the entire Office suite. Check out Mastering VBA for Microsoft Office 365 today!

More WordTips (ribbon)

Understanding Precedence

Formulas created in a macro have a specific order in which operations are performed. This is known as precedence, as ...

Discover More

Renaming a Macro

Want to give your macros a different name than they currently use? It's easy to do using the VBA Editor as described here.

Discover More

Selecting to the Next Punctuation Mark

Writing macros often involves selecting different parts of your document so that some sort of processing can be ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, 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 seven more than 1?

2026-08-01 08:13:59

jamies

Maybe add abilities to the code :
To set the time as GMT
And not to include daylight saving adjustment in that time
Have the time set as an offset from the local time - such as for the time into a shift session ( maybe more than 24 hours ?)
Have time elapsed work around the local change for DST
UTC
Common Era (CE)
Holocene Human Era (HE) calendar
Muslim calendar) (AH)

OK, ignore the occasional 61st second in the last minute of the last day of the year, or June !

And leave the Vedic, Gregorian, Jewish, Islamic, Indian, Chinese, and Julian Calendars, and other complex systems, including Astronomical ones to those needing to use them.

Universal Time (UT): Solar time based on the rotation of Earth, adjusted to the prime meridian at Greenwich.
Sidereal Time: Time measured by the daily motion of stars relative to the vernal equinox rather than the Sun.
Julian Date (JD): A continuous count of days and fractions of a day since noon on January 1, 4712 BCE,
used to avoid calendar date shifts.
Ephemeris Time
Dynamical Time:
Uniform time

Just - when dealing with dates - remember, while the UTC is widely understood, and accepted for international and foreign communication, just because the boss expects that, doesn't mean it is acceptable to use it in all cases, or locations.

Indeed there is the 360 day year - and 12 x 30 day months - the exclusion of some "holidays", or "Holy days" from possible business calendars

And - from bankers - actions to be performed on the same day of every month - when first done on the 31st day of a month, and is a shift 8 hours if from midnight to 8 a,m - when the clocks go back - leaving the logs of entries and computer actions with multiple streams of timestamps for the repeated hour !

Oh the confusion possible when dealing with dates and times and government decrees that change dates, or times for processes, and historical references -
without even the Excel 1900 and 1904 and 29th February 1900 confusion, let alone Windows built in, but alterable assumption that 24/3/25 is 24th March 2025, and 26/4/40 is 26th April 1940
and language/ country formatting expectations

or - currency, or monthnames
=TEXT(A1, "[$-fr-FR]mmm")

or the LCID coding
TEXT(A1;"[$-040C]mmm")


This Site

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

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, 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.