当我们尝试从日期中提取小时值时,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中文网其他相关文章!