2015-11-06 108 views
0

從用戶界面,用戶可以選擇一個日期並點擊提交按鈕,根據輸入字段如何顯示下一個30天的記錄爲什麼DATE_ADD和str_to_date沒有返回任何結果?

這是我sqlfiddle http://sqlfiddle.com/#!9/dbcd9/1

我一直在使用DATE_ADD嘗試和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) 

但它爲什麼不顯示任何數據?

回答

2

您需要使用STR_TO_DATE在其上保存的列名爲varchar日期

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); 
+0

非常感謝,工作完美。 – Kiran

0

使用str_to_date這樣的: - 在哪裏的情況下

str_to_date('01-OCT-2015','%d-%b-%Y') 

str_to_date(current_day,'%d-%b-%Y') 

使用STR_TO_DATE: -

where str_to_date(current_day,'%d-%b-%Y') 

查詢: -

where str_to_date(current_day,'%d-%b-%Y') between 
'2015-10-02' and DATE_ADD('2015-10-02',INTERVAL 1 MONTH);