MySQL NOW() Function Usage & Examples

The NOW() function in MySQL is used to retrieve the current date and time. It returns a value of type DATETIME, representing the current system date and time. It can be used to insert the current date and time in INSERT or UPDATE statements, or for comparing and filtering data. For example:

SELECT NOW(); -- 返回当前日期和时间

INSERT INTO table_name (created_at) VALUES (NOW()); -- 在插入数据时插入当前日期和时间

UPDATE table_name SET updated_at = NOW() WHERE id = 1; -- 更新数据时更新当前日期和时间
bannerAds