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.

Posted on

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

  1. Get the current date:

    SELECT CURRENT_DATE();
    

    This returns the current date when the query is executed.

  2. Use CURRENT_DATE in an INSERT statement:

    INSERT INTO orders (order_date) VALUES (CURRENT_DATE());
    

    This inserts the current date into the orders table.

  3. 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.

  4. Compare CURRENT_DATE to a fixed date:

    SELECT CURRENT_DATE() = '2023-01-15';
    

    This compares the current date with January 15, 2023.

  5. Use CURDATE() as an alias of CURRENT_DATE():

    SELECT CURDATE();
    

    Both CURDATE() and CURRENT_DATE() return the same current date.

Other Similar Functions

  • CURDATE() - Alias for CURRENT_DATE()
  • NOW() - Current date and time
  • SYSDATE() - Current date and time
  • CURRENT_TIMESTAMP() - Current timestamp

So CURRENT_DATE() and CURDATE() both provide a simple way to get the current date in MySQL.