get records from today in mysql

How to Get Records from Today in MySQL

Sometimes you may need to get rows from today or select records for today. It is very easy to get records from today in MySQL, even though there is no built-in function for it. Here’s the SQL query to get todays data in MySQL.

 

How to Get Records from Today in MySQL

Here are the steps to get records from today in MySQL. Let’s say you have the following table orders(order_date, amount) that contains a list of all orders.

mysql> create table orders(order_date date, sale int);

mysql> insert into orders(order_date, sale)
     values('2020-06-10',250),
     ('2020-06-11',450),
     ('2020-06-12',350),
     ('2020-06-13',220),
     ('2020-06-14',210),
     ('2020-06-15',200);

mysql> select * from orders;
+------------+------+
| order_date | sale |
+------------+------+
| 2020-06-10 |  250 |
| 2020-06-11 |  450 |
| 2020-06-12 |  350 |
| 2020-06-13 |  220 |
| 2020-06-14 |  210 |
| 2020-06-15 |  200 |
+------------+------+

Bonus Read : How to Get Records from Last 10 Minutes

 

How to Get records from today in MySQL

Here’s the SQL query to get records fro today.

mysql> select * from orders
       where date(order_date) = current_date;
+------------+------+
| order_date | sale |
+------------+------+
| 2020-06-15 |  200 |
+------------+------+

Bonus Read : How to Get Records from Last 7 Days in MySQL

In the above query we select those records where order_date’s date is equal to current date. We use DATE function to get date value from column order_date. It is useful if your column is a datetime field. If your column is a date field, then you don’t need to use DATE function. We also use system function current_date to get the latest date value.

Ubiq makes it easy to visualize data in minutes, and monitor in real-time dashboards. Try it Today!

mm

About Ubiq

Ubiq is a powerful dashboard & reporting platform. Build dashboards, charts & reports for your business in minutes. Try it for free!