Home  >  Article  >  Database  >  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
PHPzforward
2023-08-23 19:25:021079browse

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)

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete