EN
MySQL - HOUR() function example
0
points
In this article, we would like to show you HOUR()
function example in MySQL.
Syntax:
SELECT HOUR('YYYY-MM-DD hh:mm:ss');
Where:
YYYY
- four-digit year format, e.g.2021
,MM
- month number (counted from01
to12
),DD
- day number (from01
to31
- depending on the month),hh
- hour number (from00
to24
),mm
- minute number (from00
to59
),ss
- second number (from00
to59
).
Practical examples
1. With DATETYPE
type:
In this example, we will use HOUR()
function to display only an hour from a DATETIME
.
Query:
SELECT HOUR('2021-01-01 11:41:31');
Result:
2. With TIME
type:
In this example, we will use HOUR()
function to display only an hour from a TIME
.
Query:
SELECT HOUR('838:00:00');
Note:
When used with
TIME
type, theHOUR()
function can return values from0
to838
.