MySQL CURDATE() Function

Definition and Usage

The CURDATE() function returns the current date.

Syntax

CURDATE()

Instance

Example 1

Here is the SELECT statement:

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

The result is similar to:

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(50) NOT NULL,
OrderDate datetime NOT NULL DEFAULT CURDATE(),
PRIMARY KEY (OrderId)
)

Please note that the OrderDate column specifies CURDATE() 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 column.

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

INSERT INTO Orders (ProductName) VALUES ('Computer')

"Orders" table will look like this:

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