Home > Database > Mysql Tutorial > body text

How to use mysql now

藏色散人
Release: 2020-10-26 15:34:54
Original
3147 people have browsed it

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()
Copy after login

Example

The following is the SELECT statement:

SELECT NOW(),CURDATE(),CURTIME()
Copy after login

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)
)
Copy after login

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')
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template