mysql now is a function used to return the current date and time. Its statement usage is such as "SELECT NOW(), CURDATE(), CURTIME()".
Recommended: "mysql video tutorial"
MySQL NOW() function
Definition and usage
NOW() returns the current date and time.
Syntax
NOW()
Example
The following is the SELECT statement:
SELECT NOW(),CURDATE(),CURTIME()
The result is as follows:
Example
The following SQL creates the "Orders" table with a datetime column (OrderDate):
CREATE TABLE Orders ( OrderId int NOT NULL, ProductName varchar(50) NOT NULL, OrderDate datetime NOT NULL DEFAULT NOW(), PRIMARY KEY (OrderId) )
Please note that the OrderDate column specifies NOW() as the default value. As a result, when you insert a row into the table, the current date and time are automatically inserted into the columns.
Now, we want to insert a record into the "Orders" table:
INSERT INTO Orders (ProductName) VALUES ('Jarlsberg Cheese')
The "Orders" table will look like this:
The above is the detailed content of How to use mysql now. For more information, please follow other related articles on the PHP Chinese website!