totn MariaDB Functions

MariaDB: HOUR Function

This MariaDB tutorial explains how to use the MariaDB HOUR function with syntax and examples.

Description

The MariaDB HOUR function returns the hour portion of a date value.

Syntax

The syntax for the HOUR function in MariaDB is:

HOUR( date_value )

Parameters or Arguments

date_value
A time or datetime value from which to extract the hour.

Note

  • The HOUR function returns the hour (a number ranging from 0 to 838) given a date value.
  • Since a time value can range from -838:59:59' to '838:59:59', the HOUR function can return values up to 838 (ie: higher than 23).
  • See also the EXTRACT, YEAR, QUARTER, MONTH, WEEK, DAY, MINUTE, SECOND, and MICROSECOND functions.

Applies To

The HOUR function can be used in the following versions of MariaDB:

  • MariaDB 10

Example

Let's look at some MariaDB HOUR function examples and explore how to use the HOUR function in MariaDB.

For example:

SELECT HOUR('2014-05-19 09:11:18.000004');
Result: 9

SELECT HOUR('2014-05-19 14:17:05');
Result: 14

SELECT HOUR('12:05:06');
Result: 12

SELECT HOUR('838:59:59');
Result: 838

This last HOUR example would display the hour portion of the current system time (current system time is returned by the CURTIME function).

SELECT HOUR(CURTIME());