-4

I have a mysql record with the columns start_date and end_date. Now I have a date (as example 2017-08-03) and i want to ask if this date is between the start_date and end_date in my mysql table.

Is this possible?

Mathis Hüttl
  • 127
  • 3
  • 18
  • select * from tab where start_date<='2017-08-03' and end_Date>='2017-08-03' – Imran Ahmad Shahid Aug 03 '17 at 09:27
  • You can use WHERE date BETWEEN start_date AND end_date. https://stackoverflow.com/questions/1080207/mysql-select-all-data-between-two-dates – theCakeCoder Aug 03 '17 at 09:28
  • SELECT * FROM `objects` WHERE (date BETWEEN start_date_field AND end_date_field) – Krishna Gupta Aug 03 '17 at 09:29
  • 3
    Possible duplicate of [Mysql: Select all data between two dates](https://stackoverflow.com/questions/1080207/mysql-select-all-data-between-two-dates) – theCakeCoder Aug 03 '17 at 09:29
  • Instead of naively asking “is this possible”, next time please just type your question title into Google ... And please go read [ask] - among other things, it explains to you what minimal effort you are expected to make _before_ asking here. – CBroe Aug 03 '17 at 09:33
  • Possible duplicate of [How to check if a date is between date1 and date2 using mysql?](https://stackoverflow.com/questions/8904597/how-to-check-if-a-date-is-between-date1-and-date2-using-mysql) – Ignatius Aug 03 '17 at 10:37

3 Answers3

5

Use between:

SELECT * FROM events 
  WHERE '2012-01-18' between start_date AND end_date

BTW: Take care of time part if start and end are datetime types

Jens
  • 67,715
  • 15
  • 98
  • 113
1

You can use this:

SELECT * FROM events 
  WHERE start_date<='2012-01-18'
  AND end_date>='2012-01-18'
Chandra Kumar
  • 4,127
  • 1
  • 17
  • 25
1
SELECT *
FROM `yourtable`
WHERE (your_found_date BETWEEN 'start_date' AND 'end_date')
H.M Maruf
  • 65
  • 12