searching data between dates stored in varchar in mysql

后端 未结 6 1166
我寻月下人不归
我寻月下人不归 2020-12-18 05:45

I am storing my dates in column server_date_time in varchar in dd/mm/yyyy format and i want to fetch the records lying between some dates so i have

6条回答
  •  醉酒成梦
    2020-12-18 06:30

    STR_TO_DATE is enough. DATE_FORMAT changes it back to VARCHAR

    SELECT...
    FROM...
    WHERE str_to_date(substr(server_date_time,1,10),'%d/%m/%Y') 
             BETWEEN '29/09/2012' AND '07/10/2012'
    

    when dealing date please use DATE or DATETIME data type. This will avoid you from doing casting which affects the performance of the query.

提交回复
热议问题