Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the previous day records from mysql table?

Tags:

mysql

I am trying to fetch previous day records from table but I am not finding how to do it exactly. Need your help please..

Table: RECORD_DATA

id       creationDate    
1   | 2013-05-03 04:03:35 |    
2   | 2013-05-03 04:03:35 | 

Now I need to get all the records that were created on 2013-05-03. Time can be anything. So my query should have LIKE operator.

I am using below query and it gives me empty set.

select creationDate from RECORD_DATA 
where creationDate LIKE DATE_SUB(STR_TO_DATE('2012-04-05','%d/%m/%Y'),INTERVAL 1 DAY);
like image 447
user001 Avatar asked May 04 '13 09:05

user001


Video Answer


1 Answers

Fairly simple when done with SQL, just add the condition

WHERE creationDate BETWEEN CURDATE() - INTERVAL 1 DAY AND CURDATE()

There is no need to convert creationDate as it is already a date :). And i belive that this will be the fastest way to check it (which will matter if you go over large data sets).

like image 98
Tymoteusz Paul Avatar answered Oct 06 '22 23:10

Tymoteusz Paul