Get the App
SLTechnology News&Howtos  ›  Database  › 

The usage of mysql now

Shulou Source: shulou.com Published: 2022-06-01 02:12:02 10月03日 Update

This article mainly introduces the usage of mysql now, which can be used for reference. Friends who need it can refer to it. I hope you will learn a lot after reading this article. Next, let the editor take you to learn about it.

Mysql now is a function that returns the current date and time with statements such as "SELECT NOW (), CURDATE (), CURTIME ()".

MySQL NOW () function

Definition and usage

NOW () returns the current date and time.

Grammar

NOW ()

Example

Here is the SELECT statement:

SELECT NOW (), CURDATE (), CURTIME ()

The results are as follows:

Example

The following SQL creates a "Orders" table with a date-time column (OrderDate):

CREATE TABLE Orders (OrderId int NOT NULL,ProductName varchar (50) NOT NULL,OrderDate datetime NOT NULL DEFAULT NOW (), PRIMARY KEY (OrderId))

Notice that the OrderDate column specifies NOW () as the default value. As a result, the current date and time are automatically inserted into the column when you insert a row into the table.

Now we want to insert a record in the "Orders" table:

INSERT INTO Orders (ProductName) VALUES ('Jarlsberg Cheese')

The "Orders" table will look like this:

Thank you for reading this article carefully. I hope it will be helpful for everyone to share the usage of mysql now. At the same time, I also hope that you will support us, pay attention to the industry information channel, and find out if you encounter problems. Detailed solutions are waiting for you to learn!

Tags: Date time article function instance result statement value content at the same time method friend ribbon industry grammar information information channel question face channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Xiaomi Apple Microsoft Shulou Information