How Can I Select Rows in MySQL Where the Date is Today?

To select rows in MySQL where the date is today, you can use the CURDATE() function which returns the current date. You can then use this function in a WHERE clause to filter the rows based on their date column. This will only select rows where the date matches the current date, allowing you to retrieve data that is relevant for the current day. This is useful for tasks such as generating daily reports or displaying real-time data.


You can use the following basic syntax in MySQL to return all rows in a table where the date in a date column is equal to today:

SELECT *
FROM sales
WHERE DATE(sales_date) = CURDATE();

This particular example selects all rows in the table named sales where the date in the sales_date column is equal to today’s date.

Note: The CURDATE() function in MySQL returns the current date.

The following example shows how to use this syntax in practice.

Example: How to Select Rows where Date is Equal to Today in MySQL

Suppose we have the following table named sales that contains information about sales made at various grocery stores at various times:

-- create table 
CREATE TABLE sales (
  store_ID INT PRIMARY KEY,
  item TEXT NOT NULL,
  sales_date DATETIME NOT NULL
);

-- insert rows into table
INSERT INTO sales VALUES (0001, 'Oranges', '2024-02-12 03:45:00');
INSERT INTO sales VALUES (0002, 'Apples', '2020-11-25 15:25:01');
INSERT INTO sales VALUES (0003, 'Bananas', '2009-06-30 09:01:39');
INSERT INTO sales VALUES (0004, 'Melons', '2024-02-12 03:29:55');
INSERT INTO sales VALUES (0005, 'Grapes', '2023-05-19 23:10:04');

-- view all rows in table
SELECT * FROM sales;

Output:

+----------+---------+---------------------+
| store_ID | item    | sales_date          |
+----------+---------+---------------------+
|        1 | Oranges | 2024-02-12 03:45:00 |
|        2 | Apples  | 2020-11-25 15:25:01 |
|        3 | Bananas | 2009-06-30 09:01:39 |
|        4 | Melons  | 2024-02-12 03:29:55 |
|        5 | Grapes  | 2023-05-19 23:10:04 |
+----------+---------+---------------------+

This article is currently being written on 2/12/2024.

Suppose that we would like to select all rows where the date in the sales_date column is equal to today’s date.

We can use the following syntax to do so:

SELECT *
FROM sales
WHERE DATE(sales_date) = CURDATE();

Output:

+----------+---------+---------------------+
| store_ID | item    | sales_date          |
+----------+---------+---------------------+
|        1 | Oranges | 2024-02-12 03:45:00 |
|        4 | Melons  | 2024-02-12 03:29:55 |
+----------+---------+---------------------+

Notice that each of the rows in the resulting table have a date in the sales_date column that is equal to today’s date of 2/12/2024.

Additional Resources

The following tutorials explain how to perform other common tasks in MySQL:

x