如果我们尝试仅向 MySQL EXTRACT() 函数提供日期值来提取时间值,会输出什么?

如果我们尝试仅向 MySQL EXTRACT() 函数提供日期值来提取时间值,会输出什么?

当我们尝试从日期中提取小时值时,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() ,我们会得到类似的结果。

原文来自:www.php.cn
© 版权声明
THE END
喜欢就支持一下吧
点赞8 分享
评论 抢沙发
头像
欢迎您留下宝贵的见解!
提交
头像

昵称

取消
昵称表情代码图片

    暂无评论内容