Languages
[Edit]
EN

MySQL - HOUR() function example

0 points
Created by:
Dirask Community
6240

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 from 01 to 12),
  • DD -┬áday number (from 01┬áto 31 - depending on the month),
  • hh┬á- hour number (from 00 to 24),
  • mm┬á- minute number (from 00 to 59),
  • ss - second number┬á(from 00 to 59).

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:

MySQL - HOUR() function result
MySQL - HOUR() function 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');
MySQL - HOUR() function result
MySQL - HOUR() function result

Note:

When used with TIME type, the HOUR() function can return values from 0 to 838.

Related posts

MySQL - dates

Native Advertising
­čÜÇ
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

ÔŁĄ´ŞĆ­čĺ╗ ­čÖé

Join