I need to select data from mysql for last 7 days. I have field named 'date' and which have values in mm.dd.yy format. So i tried to find special mysql request to do that, but its not work with my field, i gues that beacause date in wrong format. How i can do that from php (use some variable to get mysql entries), or with custom select query ?
2条回答 默认 最新
dongtanzhu5417 2016-07-14 11:11关注You can use
STR_TO_DATE()to convert your idiosyncratic date format to a standardDATEvalue. An expression like this will do the trickSTR_TO_DATE('07.17.97', '%m.%d.%y')Then you can say
WHERE STR_TO_DATE(`date`, '%m.%d.%y') >= CURDATE() - INTERVAL 7 DAYin your query to filter items with
datevalues starting a week ago.But, if you have a lot of rows to filter you will have poor performance: this kind of WHERE clause is not sargable.
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报