MySQL 中的 MINUTE()、MICROSECOND() 和 HOUR() 函数

数据库数据库 2023-08-31 02:52:36 740
摘要: Inthisarticle,wewilldiscussabout:minute(),microsecond(),andhour()MySQLfunctions.Wewilldothesewiththehelpoftheirsyntax,usageandusecases.MySQL是一个开源的关系型数据库管理系统...

MySQL 中的 MINUTE()、MICROSECOND() 和 HOUR() 函数

In this article, we will discuss about: minute(), microsecond(), and hour() MySQL functions. We will do these with the help of their syntax, usage and use cases.

MySQL是一个开源的关系型数据库管理系统。它允许用户存储和操作数据。在MySQL中,我们可以使用函数执行特定的任务。

MINUTE()函数

The MINUTE() function returns the minute portion of a given time or datetime value. It takes one argument, which is the time or datetime value to extract the minutes.

输出格式

Output range is 0 to 59 as integer value.

Syntax

The syntax of the MINUTE() function is as follows

MINUTE(datetime)

Example-1

的翻译为:

示例-1

SELECT MINUTE(NOW());

The output will be a single number. It represents the current minute value.

Example-2

SELECT MINUTE("2023-04-02 13:06:07");

输出将是分钟值,这里是06。

Example-3

的中文翻译为:

示例-3

SELECT MINUTE("13:06:07");

输出将是分钟值,这里是06。

使用

MINUTE()函数可用于计算两个事件之间的时间长度。它可以设置特定时间戳的分钟值。

MICROSECOND()函数

The MICROSECOND() function returns the microsecond portion of a given time or datetime value. It takes one argument, which is the time or datetime value to extract the microsecond.

输出格式

Output range is 0 to 999999 as integer value.

Syntax

The syntax of the MICROSECOND() function is as follows

MICROSECOND(datetime)

Example-1

的翻译为:

示例-1

SELECT MICROSECOND(NOW());

输出将是一个单独的数字。它代表当前微秒值。

Example-2

SELECT MICROSECOND("2023-04-02 13:06:07.000005");

The output will be microsecond value which is 05 here.

Example-3

的中文翻译为:

示例-3

SELECT MICROSECOND("13:06:07.568549");

输出将是微秒值,这里是568549。

使用

The MICROSECOND() function can be useful in scenarios where high precision is required.

HOUR() function

HOUR()函数返回给定时间或日期时间值的小时部分。它接受一个参数,该参数是要提取小时的时间或日期时间值。

输出格式

输出范围为0到23的整数值。

Syntax

The syntax of the HOUR() function is as follows

HOUR(datetime)

Example-1

的翻译为:

示例-1

SELECT HOUR(NOW());

输出将是一个单一的数字。它代表当前的小时值。

Example-2

SELECT HOUR("2023-04-02 13:06:07.000005");

The output will be minute value which is 13 here.

Example-3

的中文翻译为:

示例-3

SELECT MICROSECOND("13:06:07.568549");

The output will be minute value which is 13 here.

使用

HOUR()函数在需要从时间戳中提取小时值的场景中非常有用。

我们已经讨论了这三个MySQL函数。这些函数用于处理时间或日期时间值。它们都只接受一个参数,即时间或日期时间。它们都返回一个整数值。

以上就是MySQL 中的 MINUTE()、MICROSECOND() 和 HOUR() 函数的详细内容,更多请关注其它相关文章!