首頁  >  文章  >  資料庫  >  MySQL 中的 MINUTE()、MICROSECOND() 和 HOUR() 函數

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

PHPz
PHPz轉載
2023-08-29 21:29:07940瀏覽

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() 函數的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除