Home >Database >Mysql Tutorial >How to use mysql now

How to use mysql now

藏色散人
藏色散人Original
2020-10-26 10:07:403176browse

mysql now is a function used to return the current date and time. Its statement usage is such as "SELECT NOW(), CURDATE(), CURTIME()".

How to use mysql now

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:

How to use mysql now

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:

How to use mysql now

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn