mysql: searching BETWEEN dates stored as varchar

后端 未结 6 1281
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-20 14:20

i would like to select * from table where dates between (some_date and another_date)

the problem is that the dates are stored as varchar!

6条回答
  •  旧巷少年郎
    2020-12-20 15:17

    You want to search between dates, store them as dates. By storing them as strings you're shooting yourself in the foot. You'd basically need to extract date part from the string (using SUBSTR() or LEFT() ) and parse it to date format (using STR_TO_DATE()).

    The performance of such solution will be appaling.

    STR_TO_DATE(LEFT(reporttime,LOCATE(' ',reporttime)),'%m/%d/%Y') BETWEEN '2010-07-28' AND '2010-07-29'

提交回复
热议问题