Answer the question
In order to leave comments, you need to log in
How to select a record from the database by time interval?
Good day everyone!
Recently, a new project was given - and faced with the following task
. The user of the site can create a thread of the event, and at the same time indicate the date and time of its start, as well as the date and time of its end.
Well, then the server should show
these events, but - those events, the start date and time of which has not yet come - do not need to be shown
That's actually the question - how best to implement it in the database,
I thought like this:
id
event_text
date_start (DATETIME)
date_end (DATETIME)
and then compare in sql query -
SELECT * FROM table WHERE date_start<CURDATE() AND date_end>CURDATE()
Answer the question
In order to leave comments, you need to log in
You think everything is correct, and implement it, only the type of the field is not DATETIME, but DATE, then everything will work in your example, but this is only if you compare by date. Or use DATETIME and NOW() to both date and time
SELECT * FROM start < NOW() AND stop > NOW()
can be compared like this
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question