M
M
Matthew Stafford2019-04-10 21:28:49
MySQL
Matthew Stafford, 2019-04-10 21:28:49

How to get data for today, yesterday, the day before yesterday... day?

How to get data for, for example, only yesterday?

My date is stored in Y-m-d H:i:s.
Try this, but I get nothing in response:

SELECT * FROM `payments` WHERE `date` = DATE_SUB(NOW(), INTERVAL 1 DAY)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Samsonov, 2019-04-10
@matthewstafford

There must be a date range condition

SELECT * 
FROM `payments` 
WHERE `date` BETWEEN DATE(DATE_SUB(NOW(), INTERVAL 1 DAY)) AND DATE(NOW());

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question