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

How to Select Rows with Today’s Date in MySQL

Introduction: Efficiently Filtering Data by Date in MySQL

In the world of data management, selecting records based on a specific date is one of the most common tasks required of a database system. When dealing with dynamic data—such as transactional logs, user activity records, or daily sales—it is often essential to isolate only the information relevant to the current day. Achieving this efficiently in MySQL requires utilizing built-in date and time functions that dynamically determine the system’s current date, enabling instantaneous filtering regardless of when the query is executed. This process is crucial for generating accurate daily reports, monitoring real-time activity, or powering time-sensitive application features.

The core requirement is to select rows in MySQL where the date column matches the current date precisely. This is accomplished by using the CURDATE() function, which returns the current date without any time component. By incorporating CURDATE() within a WHERE clause, we can create a powerful filter that retrieves data relevant only for the current day. This method is fundamental for many daily operational tasks, ensuring that only the most timely information is retrieved, which is useful for generating daily reports or displaying real-time data feeds.

Understanding the nuances of date handling in SQL is vital for database performance and data integrity. While seemingly straightforward, dealing with date comparisons can introduce subtle errors if the data types or functions are mismatched. Our goal is to provide a clean, reliable, and optimized query that handles this requirement seamlessly. The solution presented here is widely applicable across various MySQL versions and ensures that only data whose date portion matches the exact current date is retrieved, thereby streamlining operations like generating daily sales metrics or compiling login statistics for the day.


The Fundamental Syntax for Selecting Today’s Data

The simplest and most direct method to select rows where a DATETIME or TIMESTAMP column matches the current date involves using a combination of DATE() and CURDATE() functions within the WHERE clause. This combination is essential because it ensures that you are comparing two values that are strictly date types, thus correctly filtering out the time components that might otherwise prevent a successful match. This structure is universally recognized for its clarity and accuracy when the column being queried contains full timestamps.

The key to this method is the application of the DATE() function to the column you are querying. By wrapping the column name (e.g., sales_date) in DATE(), you effectively strip away the hourly, minute, and second components, leaving only the ‘YYYY-MM-DD’ information. This normalized value can then be reliably compared to the output of CURDATE(), which also provides only the current date.

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 extracted from the sales_date column is equal to today’s date. This method is highly effective for quick queries, though as we will discuss later, there are performance optimizations for extremely large tables. It is important to remember that the CURDATE() function in MySQL returns the current date based on the database server’s local time setting.

Deconstructing the MySQL Date Functions

To utilize time-based queries effectively in SQL, a clear understanding of the roles of the specific date functions is necessary. The function CURDATE() is a system function that interrogates the database server’s clock and returns the calendar date at the time of execution. For example, if today is October 27, 2024, CURDATE() returns the string ‘2024-10-27’. This is the target value against which all records must be matched.

The function DATE() is a utility function used to manipulate a DATETIME or TIMESTAMP value. Its sole purpose in this context is to guarantee that the value from the database column is reduced to a pure date format before comparison. If your data column contains ‘2024-02-12 15:30:00’, applying DATE() converts it to ‘2024-02-12’. This normalization is critical; without it, the query would attempt to match the full timestamp against the date provided by CURDATE(), resulting in zero matches unless the timestamp happened to be exactly at midnight (00:00:00).

The application of the DATE() function to the column is what ensures the success of this straightforward method. However, because we are using a function on the column itself, we must be aware of potential indexing limitations. When MySQL processes a query like this, it must calculate the DATE() result for every single row before it can apply the filter, which bypasses any standard index that might be present on the raw sales_date column. While effective for small datasets, this consideration is why we later introduce a high-performance alternative using date ranges.

Practical Example Setup: Creating and Populating the Table

To provide a concrete example, we will simulate a real-world scenario using a table called sales, which records sales transactions with both date and time precision. This setup ensures that we can visually confirm how the current-day filter successfully isolates the target records from older data. The table is structured to hold a unique ID, the item sold, and a DATETIME column for the sale timestamp.

The following code snippet first defines the structure of the sales table and then populates it with five sample records. Note that records 1 and 4 are deliberately set to the date 2024-02-12, while the others are set to different years, simulating a typical historical dataset. For the purposes of this demonstration, we assume the current date is 2/12/2024.

-- 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;

The table output below shows the initial state of the data. This full dataset serves as the base for our filtering operation, demonstrating clearly that the sales_date column contains full DATETIME values, making the use of the DATE() function necessary to accurately isolate records by day.

Output (All Rows):

+----------+---------+---------------------+
| 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 |
+----------+---------+---------------------+

Executing the Current Day Selection Query

Now that the table is established, we proceed to execute the primary query using the DATE(column) = CURDATE() syntax. This demonstrates how MySQL efficiently determines which rows match the current calendar day, regardless of the time they were recorded. We aim to select only the records (Oranges and Melons) corresponding to the current date, 2/12/2024.

We will use the following syntax to select all rows where the date in the sales_date column is equal to today’s date. This is the core functionality that provides the required daily data extraction:

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

The resulting output confirms the successful filtering operation. Only the two records marked with the date 2024-02-12 are returned. The other records, despite being in the table, are correctly filtered out because their date component does not match the output of CURDATE(). This clear isolation confirms the validity and accuracy of the filtering methodology for standard database use cases.

Output (Filtered Rows):

+----------+---------+---------------------+
| 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. The time portions (03:45:00 and 03:29:55) were successfully ignored during the comparison phase due to the application of the DATE() function. This is the intended behavior and the definitive solution for date-only filtering on timestamp columns.

Optimizing Performance: The Index-Friendly Range Query

As previously noted, applying a function like DATE() directly to the queried column (DATE(sales_date)) can severely degrade performance on large tables by preventing the use of indexes. For high-volume applications or databases with millions of rows, the optimized approach is to convert the selection into an inclusive lower boundary and an exclusive upper boundary query, using the raw column value for comparison.

This optimized technique leverages the fact that the current day starts precisely at midnight (00:00:00) of today and ends precisely at midnight of tomorrow. By defining this range using functions applied only to the comparison values (which are constants calculated once per query), we ensure that the column itself remains untouched, allowing MySQL to use any existing B-tree index on the sales_date column. This results in significantly faster query execution, especially when data is retrieved from a small subset of a massive table.

The index-friendly structure replaces the equality check with two boundary checks defined by CURDATE() and date arithmetic. This is the recommended practice for production environments:

SELECT *
FROM sales
WHERE sales_date >= CURDATE()
AND sales_date < CURDATE() + INTERVAL 1 DAY;

In this structure, CURDATE() returns the start of the current day (e.g., ‘2024-02-12 00:00:00’), and CURDATE() + INTERVAL 1 DAY returns the start of the next day (e.g., ‘2024-02-13 00:00:00’). The query asks for all records where the sales_date is greater than or equal to the start of today AND strictly less than the start of tomorrow, effectively capturing all 24 hours of the current day while maintaining index efficiency.

Dealing with Time Zones and Server Settings

A common pitfall in date filtering is the assumption that the server’s time zone perfectly aligns with the required application time zone. Functions like CURDATE() rely on the time zone configured for the MySQL server session. If this configuration is not properly managed, current-day data might be prematurely truncated or include records from the previous day, depending on the offset. This is particularly problematic in systems where the server runs in UTC but the data needs to be displayed in a local time zone like EST or PST.

Best practice dictates that data columns storing global event times should be saved in Coordinated Universal Time (UTC). If your column stores data in UTC, and you need to query based on a specific local time zone’s definition of “today,” you must first adjust the boundaries. While MySQL offers functions like CONVERT_TZ(), applying this to the indexed column will again negate performance benefits.

The highest performance solution for handling time zones involves calculating the local date boundaries (start of day, start of next day) in the required time zone, converting those boundaries back into UTC (if the data is stored in UTC), and then passing the resulting literal UTC timestamps into the index-friendly range query. For instance, if the application needs today’s data in EST, the application calculates the UTC timestamp equivalent of “EST Today 00:00:00” and “EST Tomorrow 00:00:00” and uses these calculated values in the WHERE clause range comparison, ensuring both accuracy and speed.

Summary of Date Selection Techniques

Successfully selecting rows based on the current date in MySQL requires choosing the appropriate strategy based on the size of your dataset and performance demands.

For standard or small datasets, the clear and intuitive syntax using function equivalence is sufficient. This relies on normalizing the column value using the DATE() function for direct comparison with the server’s current date, retrieved via CURDATE(). This provides high readability and is easy to maintain.

For large, production-level datasets where index utilization is paramount, the range query approach is mandatory. This method avoids applying functions to the indexed column, instead calculating explicit start and end boundaries for the current day using CURDATE() and date interval arithmetic. This ensures optimal query speed and is the preferred method for high-performance SQL querying practices. By understanding and correctly applying these functions and techniques, developers can accurately and efficiently manage time-sensitive data retrieval.

Cite this article

mohammed looti (2026). How to Select Rows with Today’s Date in MySQL. PSYCHOLOGICAL SCALES. Retrieved from https://scales.arabpsychology.com/stats/how-can-i-select-rows-in-mysql-where-the-date-is-today/

mohammed looti. "How to Select Rows with Today’s Date in MySQL." PSYCHOLOGICAL SCALES, 5 Jan. 2026, https://scales.arabpsychology.com/stats/how-can-i-select-rows-in-mysql-where-the-date-is-today/.

mohammed looti. "How to Select Rows with Today’s Date in MySQL." PSYCHOLOGICAL SCALES, 2026. https://scales.arabpsychology.com/stats/how-can-i-select-rows-in-mysql-where-the-date-is-today/.

mohammed looti (2026) 'How to Select Rows with Today’s Date in MySQL', PSYCHOLOGICAL SCALES. Available at: https://scales.arabpsychology.com/stats/how-can-i-select-rows-in-mysql-where-the-date-is-today/.

[1] mohammed looti, "How to Select Rows with Today’s Date in MySQL," PSYCHOLOGICAL SCALES, vol. X, no. Y, ص Z-Z, January, 2026.

mohammed looti. How to Select Rows with Today’s Date in MySQL. PSYCHOLOGICAL SCALES. 2026;vol(issue):pages.

Download Post (.PDF)
Slide Up
x
PDF
Scroll to Top