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
.
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
.
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