Home > Database > Mysql Tutorial > What will MySQL return if we include time components and date components in the parameters of the DATEDIFF() function?

What will MySQL return if we include time components and date components in the parameters of the DATEDIFF() function?

PHPz
Release: 2023-08-23 19:25:02
forward
1166 people have browsed it

What will MySQL return if we include time components and date components in the parameters of the DATEDIFF() function?

MySQL DATEDIFF() function also works with date and time values, but it ignores time values. Therefore, even if we include the time value in the DATEDIFF() function, MySQL will ignore the time value and return the difference between the dates in days.

mysql> Select DATEDIFF('2018-10-22 04:05:36','2017-10-22 03:05:45');
+-------------------------------------------------------+
| DATEDIFF('2018-10-22 04:05:36','2017-10-22 03:05:45') |
+-------------------------------------------------------+
|                                                   365 |
+-------------------------------------------------------+
1 row in set (0.00 sec)

mysql> Select DATEDIFF('2017-10-22 04:05:36','2017-10-22 03:05:45');
+-------------------------------------------------------+
| DATEDIFF('2017-10-22 04:05:36','2017-10-22 03:05:45') |
+-------------------------------------------------------+
|                                                     0 |
+-------------------------------------------------------+
1 row in set (0.00 sec)
Copy after login

The above query shows that the DATEDIFF() function ignores time values ​​when calculating the difference between dates.

The above is the detailed content of What will MySQL return if we include time components and date components in the parameters of the DATEDIFF() 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