How to use the MySQL CURRENT_DATE() function
The CURRENT_DATE() function in MySQL returns the current date in ‘YYYY-MM-DD’ format. It is an alias for the CURDATE() function.
The CURRENT_DATE() function in MySQL returns the current date in ‘YYYY-MM-DD’ format. It is an alias for the CURDATE() function.
Syntax
The syntax for CURRENT_DATE() is:
CURRENT_DATE()
It takes no arguments.
Examples
-
Get the current date:
SELECT CURRENT_DATE();This returns the current date when the query is executed.
-
Use CURRENT_DATE in an INSERT statement:
INSERT INTO orders (order_date) VALUES (CURRENT_DATE());This inserts the current date into the orders table.
-
Select records where date field equals today’s date:
SELECT * FROM time_data WHERE date = CURRENT_DATE();This returns all records where the date column matches today’s date.
-
Compare CURRENT_DATE to a fixed date:
SELECT CURRENT_DATE() = '2023-01-15';This compares the current date with January 15, 2023.
-
Use CURDATE() as an alias of CURRENT_DATE():
SELECT CURDATE();Both
CURDATE()andCURRENT_DATE()return the same current date.
Other Similar Functions
CURDATE()- Alias forCURRENT_DATE()NOW()- Current date and timeSYSDATE()- Current date and timeCURRENT_TIMESTAMP()- Current timestamp
So CURRENT_DATE() and CURDATE() both provide a simple way to get the current date in MySQL.