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中,我們可以使用函數來執行特定的任務。
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.
The syntax of the MINUTE() function is as follows
MINUTE(datetime)
SELECT MINUTE(NOW());
The output will be a single number. It represents the current minute value.
SELECT MINUTE("2023-04-02 13:06:07");
輸出將是分鐘值,這裡是06。
SELECT MINUTE("13:06:07");
輸出將是分鐘值,這裡是06。
MINUTE()函數可用來計算兩個事件之間的時間長度。它可以設定特定時間戳的分鐘值。
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.
The syntax of the MICROSECOND() function is as follows
MICROSECOND(datetime)
SELECT MICROSECOND(NOW());
輸出將會是一個單獨的數字。它代表當前微秒值。
SELECT MICROSECOND("2023-04-02 13:06:07.000005");
The output will be microsecond value which is 05 here.
SELECT MICROSECOND("13:06:07.568549");
輸出將是微秒值,這裡是568549。
The MICROSECOND() function can be useful in scenarios where high precision is required.
HOUR()函數傳回給定時間或日期時間值的小時部分。它接受一個參數,該參數是要提取小時的時間或日期時間值。
輸出範圍為0到23的整數值。
The syntax of the HOUR() function is as follows
HOUR(datetime)
SELECT HOUR(NOW());
輸出將會是一個單一的數字。它代表當前的小時值。
SELECT HOUR("2023-04-02 13:06:07.000005");
The output will be minute value which is 13 here.
SELECT MICROSECOND("13:06:07.568549");
The output will be minute value which is 13 here.
HOUR()函數在需要從時間戳記中提取小時值的場景中非常有用。
我們已經討論了這三個MySQL函數。這些函數用於處理時間或日期時間值。它們都只接受一個參數,即時間或日期時間。它們都會傳回一個整數值。
以上是MySQL 中的 MINUTE()、MICROSECOND() 和 HOUR() 函數的詳細內容。更多資訊請關注PHP中文網其他相關文章!