Languages
[Edit]
EN

MySQL - HOUR() function example

0 points
Created by:
Dharman
338

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