NOW() function returns the current timestamp of the server, that is, the current date and time. It can be called directly in the SQL query: Get the current timestamp: SELECT NOW(); Insert the timestamp: INSERT INTO.. . VALUES (NOW());Compare timestamps: SELECT * FROM ... WHERE created_at > NOW() - INTERVAL 1 HOUR;
# #Usage of NOW() function in MySQL
NOW() function overview
NOW() function returns the current timestamp of the server, that is, the current date and time. It is a parameterless function, which means it does not require any input to execute.Usage
The use of the NOW() function is very simple, just call it directly in the SQL query, as shown below:<code>SELECT NOW();</code>
Output
The output will be a string containing the current date and time in the format "YYYY-MM-DD HH:MM:SS", for example:<code>2023-03-08 14:32:15</code>
Other usage
In addition to directly returning the current timestamp, the NOW() function can also be used:Examples
Here are some examples showing how to use the NOW() function:<code>SELECT NOW();</code>
<code>INSERT INTO my_table (created_at) VALUES (NOW());</code>
<code>SELECT * FROM my_table WHERE created_at > NOW() - INTERVAL 1 HOUR;</code>This query will select all rows created within the past hour.
The above is the detailed content of How to use now() in mysql. For more information, please follow other related articles on the PHP Chinese website!