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);
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With