Home > Database > Mysql Tutorial > body text

What will be the output if we try to extract a time value by providing only a date value to the MySQL EXTRACT() function?

WBOY
Release: 2023-09-13 12:53:02
forward
1233 people have browsed it

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

When we try to extract hour value from date, EXTRACT() function will give output 0 with warning as shown in the example given below -

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)
Copy after login

Now when we try to extract minute value from date, EXTRACT() function will give century value in date as output with warning as shown in the example given below-

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)
Copy after login

Now when we try to extract seconds value from date, EXTRACT() function will give year value as output with warning as shown in the example given below-

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)
Copy after login

Trying to get the time value (hours, minutes and seconds) from the current date, i.e. by using Curdate() at the date position, we will get similar results.

The above is the detailed content of What will be the output if we try to extract a time value by providing only a date value to the MySQL EXTRACT() function?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template