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!