MySQL curdate () function

Source: Internet
Author: User

Definition and usage

The Curdate () function returns the current date.

Grammar
Curdate ()
Example 1

Here is the SELECT statement:

SELECT now (), Curdate (), Curtime ()

The results are similar:

Now
() curdate () curtime ()
2008-12-29 16:25:46 2008-12-29 16:25:46
Example 2

The following SQL creates an "Orders" table with a datetime column (OrderDate):

CREATE TABLE Orders (OrderId int not null,productname varchar (NO) null,orderdate datetime not NULL DEFAULT curdate (), P Rimary KEY (OrderId))

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

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

INSERT into Orders (ProductName) VALUES (' computer ')

The Orders table will look like this:

OrderId ProductName OrderDate
1 ' Computer ' 2008-12-29

MySQL Date function

MySQL curdate () function

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.