Reputation:
From User Interface , user can select a date and click on the submit button , based on the input field how to display next 30 days records ??
This is my sqlfiddle http://sqlfiddle.com/#!9/dbcd9/1
i have tried using DATE_ADD and str_to_date
select * from historical_data where current_day between
str_to_date('2015-10-02','%Y-%m-%d') and DATE_ADD(str_to_date('2015-10-02','%Y-%m-%d'),
INTERVAL 1 MONTH)
But why it is not displaying any data ??
Upvotes: 0
Views: 109
Reputation: 6661
use str_to_date
like that :-
str_to_date('01-OCT-2015','%d-%b-%Y')
or
str_to_date(current_day,'%d-%b-%Y')
use str_to_date on where case :-
where str_to_date(current_day,'%d-%b-%Y')
query :-
where str_to_date(current_day,'%d-%b-%Y') between
'2015-10-02' and DATE_ADD('2015-10-02',INTERVAL 1 MONTH);
Upvotes: 0
Reputation: 44844
You need to use str_to_date on on the column name which is saved as varchar dates
select * from historical_data
where str_to_date(current_day,'%m-%b-%Y')
between
'2015-10-02' and DATE_ADD('2015-10-02',INTERVAL 1 MONTH);
Upvotes: 1