當我們嘗試從日期中提取小時值時,EXTRACT() 函數將給出輸出0 並帶有警告,如下面給出的示例所示-
mysql> Select EXTRACT(Hour from '2017-10-20'); +---------------------------------+ | EXTRACT(Hour from '2017-10-20') | +---------------------------------+ | 0 | +---------------------------------+ 1 row in set, 1 warning (0.00 sec) mysql> Show Warnings; +---------+------+----------------------------------------------+ | Level | Code | Message | +---------+------+----------------------------------------------+ | Warning | 1292 | Truncated incorrect time value: '2017-10-20' | +---------+------+----------------------------------------------+ 1 row in set (0.00 sec)
現在,當我們嘗試從日期中提取分鐘值時,EXTRACT() 函數將給出日期中的世紀值作為輸出,並帶有警告,如下面給出的示例所示- p>
mysql> Select EXTRACT(Minute from '2017-10-20'); +-----------------------------------+ | EXTRACT(Minute from '2017-10-20') | +-----------------------------------+ | 20 | +-----------------------------------+ 1 row in set, 1 warning (0.00 sec) mysql> Show Warnings; +---------+------+----------------------------------------------+ | Level | Code | Message | +---------+------+----------------------------------------------+ | Warning | 1292 | Truncated incorrect time value: '2017-10-20' | +---------+------+----------------------------------------------+ 1 row in set (0.00 sec)
現在,當我們嘗試從日期中提取秒值時,EXTRACT() 函數將給出年份值作為輸出,並帶有警告,如下面給出的示例所示-
mysql> Select Extract(Second from '2017-10-20'); +-----------------------------------+ | Extract(Second from '2017-10-20') | +-----------------------------------+ | 17 | +-----------------------------------+ 1 row in set, 1 warning (0.00 sec) mysql> Show Warnings; +---------+------+----------------------------------------------+ | Level | Code | Message | +---------+------+----------------------------------------------+ | Warning | 1292 | Truncated incorrect time value: '2017-10-20' | +---------+------+----------------------------------------------+ 1 row in set (0.00 sec)
嘗試從當前日期獲取時間值(小時、分鐘和秒),即透過在日期位置使用Curdate() ,我們會得到類似的結果。
以上是如果我們嘗試僅向 MySQL EXTRACT() 函數提供日期值來提取時間值,會輸出什麼?的詳細內容。更多資訊請關注PHP中文網其他相關文章!