0

ID |    STARTS     |  ENDS
1   |  2016-04-13  |  2016-04-14
2   |  2016-04-13  |  2016-04-15
3   |  2016-04-13  |  2016-04-15
4   |  2016-04-13  |  2016-04-16
5   |  2016-04-13  |  2016-04-19

I need to get the events on 2016-04-16 . So the result should be

4   |  2016-04-13  |  2016-04-16
5   |  2016-04-13  |  2016-04-19

What will be the mysql query?

1

2 Answers 2

1

Use and:

select *
from mytable
where starts <= '2016-04-16' and '2016-04-16' <= ends;

or between:

select *
from mytable
where '2016-04-16' between starts and ends;
Sign up to request clarification or add additional context in comments.

Comments

0

Do you need events on fixed date?

  select * from yourTable
  where STARTS between '2015-01-01 00:00:00' and '2015-01-01 23:59:59'
  or ENDS between '2015-01-01 00:00:00' and '2015-01-01 23:59:59'

EDITED, try this:

 select * from yourTable
  where STARTS >='2016-04-16' and ENDS <= '2016-04-16'

1 Comment

Tell me, what exactly you need. Do you have a table with 3 coluns right? ID, STARTS and ENDS and you want to list only events that start or end on single date? Because in your exemple, to show ids 4 and 5 will show events who heppens on the interval

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.