Home >Database >Mysql Tutorial >How to use now in mysql
The NOW() function is a timestamp function in MySQL that returns the current system time and date. Its usage is NOW([format]), where format specifies the time format, and the default is YYYY-MM-DD HH:MM:SS. The returned time can be specified in ISO 8601 format, date format, or time format. The NOW() function returns the server time. The accuracy is affected by the server clock resolution and should be used with caution when comparing timestamps.
Detailed explanation of the NOW() function in MySQL
What is the NOW() function?
The NOW() function is a MySQL function that returns the current system time and date.
Usage of NOW() function
NOW() function can be used according to the following syntax:
<code>NOW([format])</code>
Where:
format
(optional): Specify the time format. If no format is specified, a timestamp in the format YYYY-MM-DD HH:MM:SS
is returned. Detailed Description
The NOW() function returns the current time, which is based on the server's host computer clock. It is a volatile function, which means it returns a new value every time it is called.
Date format
The time format returned by the NOW() function can be specified as one of the following values:
%Y -%m-%d %H:%M:%S
: ISO 8601 format %Y-%m-%d
: Date format %H:%M:%S
: Time format If no date format is specified, the NOW() function will return YYYY-MM-DD HH:MM:SS
format value.
Example
<code>SELECT NOW();</code>
Output:
<code>2023-03-08 14:30:01</code>
<code>SELECT NOW('%Y-%m-%d');</code>
Output:
<code>2023-03-08</code>
Notes
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!