Home  >  Article  >  Database  >  How to use 2-digit year value in MySQL DATEDIFF() function?

How to use 2-digit year value in MySQL DATEDIFF() function?

PHPz
PHPzforward
2023-09-05 12:09:021268browse

如何在 MySQL DATEDIFF() 函数中使用 2 位年份值?

We can use 2-digit year values ​​in a single date expression or in two date expressions used as parameters in the MySQL DATEDIFF() function.

For example, the following query uses a 2-digit year value in the first date expression, and the other date expressions have 4-digit year values.

mysql> Select DATEDIFF('18-10-22','2017-10-22');
+-----------------------------------+
| DATEDIFF('18-10-22','2017-10-22') |
+-----------------------------------+
|                               365 |
+-----------------------------------+
1 row in set (0.00 sec)

The following query uses 2-digit year values ​​in both date expressions.

mysql> Select DATEDIFF('18-10-22','17-10-22');
+---------------------------------+
| DATEDIFF('18-10-22','17-10-22') |
+---------------------------------+
|                             365 |
+---------------------------------+
1 row in set (0.00 sec)

The above is the detailed content of How to use 2-digit year value in MySQL 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