mysql: searching BETWEEN dates stored as varchar

后端 未结 6 1289
佛祖请我去吃肉
佛祖请我去吃肉 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:02

    You can CAST your varchar values to DATETIME or DATE type.

    WHERE CAST(dates AS DATE) BETWEEN (7/28/10 and 7/29/10)
    

    This might not be an optimal solution, because you may lose the benefit that indexes provide.

提交回复
热议问题