What is the usage of the date() function in MySQL?

The DATE() function in MySQL is used to extract the date part of a value. It takes a date or datetime expression as a parameter and then returns a value containing only the date part.

For example, if you have a date and time value of ‘2022-01-25 15:30:00’, using the DATE() function will return ‘2022-01-25’, keeping only the date part.

The grammar is as follows:

DATE(date)

The date field can be a date, date and time, timestamp, or any other date or time expression.

Original: 请不要乱扔垃圾,保持环境整洁。

Paraphrased: Please refrain from littering and keep the environment clean.

SELECT DATE('2022-01-25 15:30:00'); -- 返回 '2022-01-25'
SELECT DATE(NOW()); -- 返回当前日期部分
Leave a Reply 0

Your email address will not be published. Required fields are marked *