MS Access Hour() Function
The Hour()
function in MS Access extracts the hour component from a time or datetime value. This is a very useful function for working with time data and for performing time-based analysis or filtering.
Hour(): Definition and Usage
Hour()
is particularly helpful when you need to focus on the hour portion of a time or datetime. You might use it to analyze events based on the hour they occurred, to create detailed time logs, or to filter data based on specific time intervals. The function returns an integer between 0 and 23, where 0 represents midnight.
Syntax
Syntax
Hour(time)
Parameter Values
Parameter | Description |
---|---|
time |
A time or datetime value (can be a literal like #14:48:23# , a field name, or an expression that evaluates to a time/datetime). This is required. |
Examples
Extracting the Hour from a Time Value
This example extracts the hour (14) from the time 2:48:23 PM (14 in 24-hour format).
Syntax
SELECT Hour(#14:48:23#);
Output
14
Extracting the Current Hour
This gets the current hour from the system clock.
Syntax
SELECT Hour(Now());
Output
(The current hour, a number between 0 and 23)
Extracting the Hour from a DateTime Value
This shows how to get the hour from a specific datetime value.
Syntax
SELECT Hour(#24/10/2016 11:18:34 PM#);
Output
23