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