1. 程式人生 > >mysql中String型別日期比較

mysql中String型別日期比較

    1、資料庫中欄位createtime型別為String,格式為:06-08-2018 10:50:24;

    2、以createtime做條件做時間範圍內的查詢操作:

   將String轉為date:

<if test="start != null">
    and STR_TO_DATE(p.createtime,'%d-%m-%Y %H:%i:%s') &gt; STR_TO_DATE(#{start},'%d-%m-%Y %H:%i:%s')
</if>
<if test="end != null">
    and STR_TO_DATE(p.createtime,'%d-%m-%Y %H:%i:%s') &lt; STR_TO_DATE(#{end},'%d-%m-%Y %H:%i:%s')
</if>

​