Skip to content
Advertisement

Get today and yesterday data from mysql

SELECT  * FROM att_record2 WHERE  DATE(row_datentime)=DATE_SUB(CURDATE(), INTERVAL 1 DAY)  
AND out_datentime="0000-00-00 00:00:00" AND in_datentime!="0000-00-00 00:00:00"

I want to get data from today and yesterday My approch its only show yesterday record only but i want both today and yesterday please help me

Advertisement

Answer

OK, you can get yesterday and today as below functions:

mysql> select curdate() as today;
+------------+
| today      |
+------------+
| 2019-06-12 |
+------------+
1 row in set (0.00 sec)

mysql> select curdate() - interval 1 day as yesterday;
+------------+
| yesterday  |
+------------+
| 2019-06-11 |
+------------+
1 row in set (0.00 sec)

mysql> select curdate() + interval 1 day as tomorrow;
+------------+
| tomorrow   |
+------------+
| 2019-06-13 |
+------------+
1 row in set (0.00 sec)

So the complete SQL:

select  
    * 
from 
    att_record2 
where  
    date(row_datentime) >= curdate() - interval 1 day
    and date(row_datentime) <= curdate()
    and out_datentime='0000-00-00 00:00:00'
    and in_datentime!='0000-00-00 00:00:00'
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement