I
I
IceJOKER2015-12-07 21:27:52
MySQL
IceJOKER, 2015-12-07 21:27:52

What is the correct way to get data for today/tomorrow, etc.?

There is a table
Events
id title date date_to
date_to - by default NULL
You can add events only for one day or for a period from some date to some, now the questions are - did I correctly make a request to select events for today/tomorrow/week ? Doesn’t leave the feeling that you can somehow turn it more concisely)
SELECT * FROM events e

WHERE e.date = CURDATE() OR (e.date <= CURDATE() AND e.date_to >= CURDATE())

^^^
Today's
WHERE e.date = DATE_ADD(CURDATE(), INTERVAL 1 DAY) OR (e.date <= CURDATE() AND e.date_to >= CURDATE());

^^^
Tomorrow's
WHERE (e.date BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 1 WEEK)) OR (e.date <= CURDATE() AND e.date_to >= CURDATE());

^^^
Week

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Grigory Vasilkov, 2015-12-08
@gzhegow

And why is it not recommended to store the date in seeing such a normal number and choose the banal <= ?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question