-1

I want to retrieve the records from a MySQL table based on given date.

For example, 2014-10-11 is the given date, then I need records 10 days before and records 10 days after the given date.

Ex: where Date-10 days AND date+10 days.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
  • 2
    That's great. Keep up the good work. – Strawberry May 12 '15 at 12:31
  • without any code, any example rows in your database and the expected result: no help :) – Florian May 12 '15 at 12:33
  • Hi, welcome to StackOverflow. Your post will need more information and a proper question if you want an answer. At the moment we don't have much to work with. Post your current solution, some example data and a clearly defined question to be answered. – DIXONJWDD May 12 '15 at 12:37
  • Maybe this question helps: http://stackoverflow.com/questions/1080207/mysql-select-all-data-between-two-dates – Alessandro Hoss May 12 '15 at 12:47

1 Answers1

1

To add dates use interval. To convert a string to date use str_to_date(). To check if a date is between two dates, use the between keyword.

select * from table_name
where date_columnname 
between str_to_date('2014-10-11','%y-%m-%d') - INTERVAL 10 DAY
and str_to_date('2014-10-11','%y-%m-%d') + INTERVAL 10 DAY
Brino
  • 2,442
  • 1
  • 21
  • 36